当用vs2013中的 EF5来生成 实体模型之后,看到这个列被标识为 bool 类型
Mysql官方参考文档关于布尔类型的说明:
BOOL, BOOLEAN
These types are synonyms(同义词) for TINYINT(1). A value of zero is considered(认为是) false. Nonzero(不为0) values are considered true
下面是一个老外的文章,MySQL :: MySQL Connector/Net for EF binds TINYINT(1) incorrectly 他用的是EF4.3版本,我用的是EF5版本
I believe I've discovered a bug in the way the MySQL Connector for .NET maps fields of type TINYINT(1) within Entity Framework.
The database I'm working with has a number of fields used to store "enumeration values" - basically an integer that represents a specific .NET enumeration value. ie/ Open = 1, Closed = 2
Since the enumerations contain a small number of possible values (2-5), the majority of these fields are declared as the MySQL datatype TINYINT(1). In other words, we want an integer with a minimal amount of storage space and a maximum of "one character".
When we use Entity Framework 4.3 to map these TINYINT(1) fields to an "int" data type, the integer value *always* comes back as "1", regardless of the underlying storage value. The integer values 2, 3, 4, etc all get converted to 1.
If I convert the entity property's type to "string", it receives a value of "True".
It appears as though the MySQL Connector for .NET is hardcoded to treat TINYINT(1) as a boolean, regardless of the data type it's eventually bound to. TINYINT(1) should only be converted to a boolean when it's bound to a "bool" property, and nothing else. It appears as though it's trying to simulate the behavior of the "BIT" field in SQL Server, which is a completely different thing (it's not an integer, while TINYINT is).
Is this a known issue? Should I file a bug report?
翻译过来如下
他说,在EF4.3中,他用一个字段 Tinyint(1) 想去存一个 int类型的值,不管是存 1还是2,3,4 他都是变成了1
如果他在Ef的实体中把类型改为string,到了数据库却变成了 “True”
这个问题好像是发生在,通过 MySql Connector For .Net这个组件来链接Mysql的时候发生的 .
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)