Skip to content

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

Closed

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 :)

Activity

  1. danzel commented on May 6, 2014

    @danzel
    ContributorAuthor

    Infact, setting the DbType to Object before setting a string fails (It works if you set Value before DbType). So I'm thinking this is bugged

  2. changed the title [-]DbType.Object parameter cannot be an int[/-] [+]DbType.Object parameter cannot be an int (or string)[/+] on May 6, 2014
  3. franciscojunior commented on May 6, 2014

    @franciscojunior
    Member

    Yes, you are right! It is really bugged. :(

    We are working on this issue in #201. We also have discussions on different levels, but related to this in #146 and #125

    Regarding this specific problem, I talk about the solution in this comment: #201 (comment)

    I'll create a pull request with this fix so you can give it a try.

    Thanks for your feedback on this!

  4. danzel commented on May 6, 2014

    @danzel
    ContributorAuthor

    Thanks, will close this off and follow #201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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