How to get a bigint to a long object property from SQL Server using Dapper?

asp.net c# dapper sql-server

Question

I have a bigint in my table and when I try to do a select using Dapper, it is not working. I found a tip that said to cast to numeric, but that is throwing a invalid cast error.

What is the correct cast to use with dapper?

Accepted Answer

Just type as long:

    public void TestNakedBigInt()
    {
        long foo = 12345;
        var result = connection.Query<long>("select @foo", new {foo}).Single();
        foo.IsEqualTo(result);
    }

    public void TestBigIntMember()
    {
        long foo = 12345;
        var result = connection.Query<WithBigInt>(@"
declare @bar table(Value bigint)
insert @bar values (@foo)
select * from @bar", new {foo}).Single();
        result.Value.IsEqualTo(foo);
    }
    class WithBigInt
    {
        public long Value { get; set; }
    }



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why