除$ P $如何用PTED EF code首先枚举类型 [英] How is interpreted an enum type with EF Code First
本文介绍了除$ P $如何用PTED EF code首先枚举类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是一个模型:
Public class Person
{
[Key]
Public int PersonId { get; set: }
Public int Age { get; set; }
Public ColorEnum FavoriteColor { get; set; }
}
Public Enum ColorEnum
{
Red = 1,
Green = 2,
Blue = 3
}
是否有可能在实体框架code首先使用人模型来生成相应的表?怎么样ColorEnum类型?
Is it possible for Entity Framework Code First to use the Person model to generate the corresponding table? What about the ColorEnum type?
感谢
推荐答案
EF 4.3不支持枚举。但已经宣布 枚举
支持与EF 5 ,这是由于一起出去.NET 4.5的到来。为了处理好与$ C $枚举C-目前首先你会做类似如下:
EF 4.3 doesn't support Enums. But is has been announced that Enum
support is coming with EF 5, which is due out alongside .NET 4.5. To handle enums with Code-First currently you'll do something like the following:
Public class Person
{
[Key]
Public int PersonId { get; set: }
Public int Age { get; set; }
public int FavoriteColorValue{ get; set;}
[NotMapped]
Public ColorEnum FavoriteColor
{
get{ return (ColorEnum)FavoriteColorValue; }
set{ FavoriteColorValue = (int)value; }
}
}
Public Enum ColorEnum
{
Red = 1,
Green = 2,
Blue = 3
}
这篇关于除$ P $如何用PTED EF code首先枚举类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文