我刚刚开始学习一些有关实体框架的知识,对ORM的了解也很少。
I am just starting to learn a bit about the entity framework and don't have much experience with ORM's.
在我的小应用程序中,我有一张桌子, sql server表有几列,包括PrimaryKey(int),Name(string)和Flag(tinyint)。
In my little app I have one table, this sql server table has several columns including a PrimaryKey (int) a Name (string) and a Flag (tinyint).
当我将此表导入到其中时,会自动为其分配Flags '数据类型为字节。很好,但是Flag确实应该是布尔值,所以我
When I imported this table into it automatically assigned the Flags' datatype as a byte. This is fine, but the Flag should really be a boolean, so I
然后出现此错误:
错误2019:指定了成员映射无效。 'MyModel.MyItem'类型的成员'MyFlag'的类型'Edm.Boolean [Nullable = True,DefaultValue =]'与$ b $不兼容b'SqlServer.tinyint [Nullable = True,DefaultValue =]'成员'MyFlag',类型为'MyModel.Store.MyItem'。
Error 2019: Member Mapping specified is not valid. The type 'Edm.Boolean[Nullable=True,DefaultValue=]' of member 'MyFlag' in type 'MyModel.MyItem' is not compatible with 'SqlServer.tinyint[Nullable=True,DefaultValue=]' of member 'MyFlag' in type 'MyModel.Store.MyItem'.
有没有办法
MyItem item = new MyItem(); item.Flag = true;并在数据库中将Flag保存为1?
and have Flag save to 1 in the database?
推荐答案您可以将 MyFlag 的数据类型更改为 bit 。
You could change the datatype of MyFlag to bit in the database.
更多推荐
在实体框架中将模型属性设置为布尔值
发布评论