开发者

Enum property mapped to a varchar column on EF June 2011 CTP

开发者 https://www.devze.com 2023-04-08 04:52 出处:网络
I\'m trying to create a model with Code First approach. I wanted to know if it\'s possible to map an Enum property to a varchar column in the database.

I'm trying to create a model with Code First approach. I wanted to know if it's possible to map an Enum property to a varchar column in the database. I know you can do it with byte, small, int, long.

This is a project for an old database and it has many columns with constraints. It would be nice to 开发者_Python百科have this structure mapped to enum values.

Thanks


No it is not possible. Enum in EF June 2011 CTP can work only with enums supported by .NET platform itself and .NET supports enum only on integral types except char. That means only byte, sbyte, short, ushort, int, uint, long, or ulong are supported. The same is true about mapping in EF. EF can map enum only to column with integer type.

You can check more about that here. It also contains description of internal types supported by EF for enum:

Similarly to CLR enums the EF enums have underlying type which is one of Edm.SByte, Edm.Byte, Edm.Int16, Edm.Int32 or Edm.Int64 with Edm.Int32 being the default underlying type if none has been specified.

You can also check my comment under that article.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号