Set model property to boolean in Entity Framework

后端 未结 2 1042
借酒劲吻你
借酒劲吻你 2020-12-14 19:01

I am just starting to learn a bit about the entity framework and don\'t have much experience with ORM\'s.

In my little app I have one table, this sql server table ha

相关标签:
2条回答
  • 2020-12-14 19:38

    I think for the tinyint you will have to make a partial class and use a separate field that appropriately read/writes to that field. However the framework will correctly interpret bit fields as boolean.

    You could try something like below as the partial..

    public partial class MyItem
    {
        public bool FlagBool
        {
            get { return Flag == 1; }
            set { Flag = value ? 1 : 0; }
        }
    }
    
    0 讨论(0)
  • 2020-12-14 19:54

    You could change the datatype of MyFlag to bit in the database.

    0 讨论(0)
提交回复
热议问题