Bro*_*ato 8 asp.net-mvc entity-framework
这是一个模型:
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
}
Run Code Online (Sandbox Code Playgroud)
Entity Framework Code First是否可以使用Person模型生成相应的表?ColorEnum类型怎么样?
谢谢
Sor*_*rax 11
EF 4.3不支持Enums.但是已经宣布将Enum
支持EF 5,它将与.NET 4.5一起推出.要使用Code-First处理枚举,您现在可以执行以下操作:
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
}
Run Code Online (Sandbox Code Playgroud)