Nils Anders
Nils Anders

Reputation: 4410

Invalid cast with dapper and decimal(10,2)

The following code give me invalid cast operation. The Qty column in my MS Sql server is of type decimal(10,2)

#region SQL Syntax

var sql = "select qty from productarticle where articleid=@articleid and productid=@productid";

#endregion

using (IDbConnection cn = Connection)
{
    cn.Open();

    return cn.Query<double>(sql, new { articleid = articleid, productid = productid }).Single();
}

If I try to return it as int, there is no problem. Any clue?

Upvotes: 2

Views: 2560

Answers (1)

gbn
gbn

Reputation: 432261

SQL decimal maps to C# decimal, not double

Upvotes: 6

Related Questions