Commit 6bda9725 authored by Marc Gravell's avatar Marc Gravell

Ensure that when processing bools we do a "!=0" test; we don't just want to...

Ensure that when processing bools we do a "!=0" test; we don't just want to store `7` as a bool - that causes problems sometimes.
parent d79d9c21
......@@ -1939,6 +1939,13 @@ public static void SetTypeMap(Type type, ITypeMap map)
{ // unbox as the data-type, then use IL-level convert
il.Emit(OpCodes.Unbox_Any, dataType); // stack is now [target][target][data-typed-value]
il.Emit(opCode); // stack is now [target][target][typed-value]
if (unboxTypeCode == TypeCode.Boolean)
{ // compare to zero; I checked "csc" - this is the trick it uses; nice
il.Emit(OpCodes.Ldc_I4_0);
il.Emit(OpCodes.Ceq);
il.Emit(OpCodes.Ldc_I4_0);
il.Emit(OpCodes.Ceq);
}
}
else
{ // use flexible conversion
......
......@@ -1937,6 +1937,27 @@ select @A
var item = connection.Query<int>("#TestProcWithIndexer", new ParameterWithIndexer(), commandType: CommandType.StoredProcedure).Single();
}
public void Issue_40_AutomaticBoolConversion()
{
var user = connection.Query<Issue40_User>("select UserId=1,Email='abc',Password='changeme',Active=cast(1 as tinyint)").Single();
user.Active.IsTrue();
user.UserID.IsEqualTo(1);
user.Email.IsEqualTo("abc");
user.Password.IsEqualTo("changeme");
}
public class Issue40_User
{
public Issue40_User()
{
Email = Password = String.Empty;
}
public int UserID { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public bool Active { get; set; }
}
class TransactedConnection : IDbConnection
{
IDbConnection _conn;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment