在实体框架中将模型属性设置为布尔值

编程入门 行业动态 更新时间:2024-10-19 19:46:01
本文介绍了在实体框架中将模型属性设置为布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我刚刚开始学习一些有关实体框架的知识,对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

  • 单击映射详细信息
  • 选择我的Flag属性
  • 将类型从字节更改为布尔值
  • 重建应用程序
  • Clicked on the Mapping Details
  • Selected my Flag property
  • Changed the Type from Byte to Boolean
  • Rebuilt the application
  • 然后出现此错误:

    错误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.

    更多推荐

    在实体框架中将模型属性设置为布尔值

    本文发布于:2023-11-13 02:05:24,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1583116.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:设置为   中将   实体   框架   属性

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!