Tinyint(byte),SmallInt(Int16) not compatible with Enum in EF5

前端 未结 2 1102
余生分开走
余生分开走 2021-02-05 04:48

Using Database first design and having tinyint (or smallint) column:

[MyEnumColumn] [tinyint] NOT NULL

I mapped this column to Enum Type in EDM

2条回答
  •  不知归路
    2021-02-05 05:13

    Well if anyone is interested the problem is in enum's default type:

    public enum MyEnumType 
    { One, Two, Three, All }
    

    Since enum defaults to type int, [Underlying Type:{Byte}] doesn't match type of [External Type] {MyEnumType:Int} so to fix it for my original tinyint field you need to define your enum like this:

    public enum MyEnumType : byte
    { One, Two, Three, All }
    

提交回复
热议问题