I have the following code:
string sql = "SELECT * FROM orders o " +
"INNER JOIN users u ON o.user_id = u.id " +
"WHERE o.ticker = @ticker AND o.user_id = @user_id";
var _orders = connection.Query(sql, new { ticker = ticker, user_id = userId });
IEnumerable<Order> orders = connection.Query<Order, User, Order>(sql,
(o, u) =>
{
u.Id = u.Id.Trim();
Order order = new Order(o.Ticker.Trim(), u, o.Type, o.Quantity, o.Price, o.IsMarketOrder, o.ExpirationDate, o.FillCompletely, o.FillImmediately);
return order;
},
new { ticker = ticker, user_id = userId }
);
return orders.ToArray<Order>();
The two "connection.Query" execute the same SQL. The difference is that the first one returns a list of DapperRows whereas the second one is a generic Query<> that multi maps the entity automatically.
Now, in the first .Query() (that returns a list of DapperRows) the boolean properties (bit in the dB) "FillImmediately" and "FillCompletely" are true or false in the class depending if they are "1" or "0" in the DB. So that works fine.
However, when using the .Query<>(), both properties are always "false". It seems that the .Query<>() can't map the bit to boolean properly.
I'm using latest version of Dapper as of today (1.42) and SQL Server 2008
Thoughts?