X Tutup
Skip to content

DbType.Object parameter cannot be an int (or string) #228

@danzel

Description

@danzel

If you create a parameter, give it DbType.Object and try set an int, it fails.
This was possible on 2.0.11 (I'm not sure if it should be possible)

Dapper will try do this if you give it a dynamic in its parameters, something like this I believe:

dynamic value = 1;
conn.Execute("SELECT :param", new { param = value });

Here is a test case:

[Test]
public void ParameterExplicitType2DbTypeObjectFromInt()
{
    using (var command = new NpgsqlCommand(@"SELECT * FROM data WHERE field_int4=:param", Conn))
    {
        var sqlParam = command.CreateParameter();
        sqlParam.ParameterName = "param";
        sqlParam.DbType = DbType.Object;
        sqlParam.Value = 1;
        command.Parameters.Add(sqlParam);
        command.ExecuteScalar();
    }
}

I'll have a go at making this work, hopefully without cludging too much :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup