Please has anyone come across the above situation with Dapper and MySQL. In all my tables in MySQL (5.1), where the data type is BIT(1) or BIT, Dapper simply return such field as ulong (UInt64). I am using MySql.Data.MySqlClient and I have no such issue with EF which is what I am trying to convert from.
请有人用Dapper和MySQL遇到上述情况。在MySQL(5.1)的所有表中,数据类型是BIT(1)或BIT,Dapper只返回ulong(UInt64)这样的字段。我正在使用MySql.Data.MySqlClient,我没有EF的问题,这是我想要转换的。
Thanks for any help.
谢谢你的帮助。
2 个解决方案
#1
3
In MySQL, the type Boolean
is mapped to Tinyint(1)
with MySQL. Perhaps you will have to cast it to Boolean
(0=false/1=true), Convert.toBoolean(UInt64)
may help you (see http://msdn.microsoft.com/en-us/library/33f2zy48.aspx).
在MySQL中,类型Boolean使用MySQL映射到Tinyint(1)。也许您必须将其强制转换为Boolean(0 = false / 1 = true),Convert.toBoolean(UInt64)可能会帮助您(请参阅http://msdn.microsoft.com/en-us/library/33f2zy48.aspx) 。
@Christian Droulers: The behaviour of SQLite is similar.
@Christian Droulers:SQLite的行为类似。
#2
0
Why don't you do the casting in your sql query ?
为什么不在sql查询中进行转换?
cast(myField using TINYINT(1)) as myField
Not sure abot the type here, but that's the way I do when my db type doesn't match my object's.
不确定在这里输入类型,但这是我的数据库类型与我的对象不匹配时的方式。
#1
3
In MySQL, the type Boolean
is mapped to Tinyint(1)
with MySQL. Perhaps you will have to cast it to Boolean
(0=false/1=true), Convert.toBoolean(UInt64)
may help you (see http://msdn.microsoft.com/en-us/library/33f2zy48.aspx).
在MySQL中,类型Boolean使用MySQL映射到Tinyint(1)。也许您必须将其强制转换为Boolean(0 = false / 1 = true),Convert.toBoolean(UInt64)可能会帮助您(请参阅http://msdn.microsoft.com/en-us/library/33f2zy48.aspx) 。
@Christian Droulers: The behaviour of SQLite is similar.
@Christian Droulers:SQLite的行为类似。
#2
0
Why don't you do the casting in your sql query ?
为什么不在sql查询中进行转换?
cast(myField using TINYINT(1)) as myField
Not sure abot the type here, but that's the way I do when my db type doesn't match my object's.
不确定在这里输入类型,但这是我的数据库类型与我的对象不匹配时的方式。