4
我有一個名爲Operation
這樣一個枚舉類型:使用實體框架映射INT列枚舉財產
[Flags]
public enum Operation
{
None = 0,
View = (1 << 0),
Add = (1 << 1),
Edit = (1 << 2),
Delete = (1 << 3),
ReservedA = (1 << 4),
ReservedB = (1 << 5),
Admin = (View | Add | Edit | Delete)
}
和表permission
包含operations
列。此表映射到這樣一個類:
[Table("rolepermission")]
public class Permission : IComparable
{
private int _id = 0;
private Operation _operations = Operation.None;
private List<UserRole> _roles = null;
public Permission()
{
_roles = new List<UserRole>();
}
[Key]
public int Id
{
get { return _id; }
set { _id = value; }
}
[EnumDataType(typeof(Operation))]
public Operation Operations
{
get { return _operations; }
set { _operations = value; }
}
}
但它不起作用。
有什麼優雅的方式可以映射它嗎?
我認爲創建一個int
型屬性不是最好的方法。
根據nathan的評論http://thedatafarm.com/blog/data-access/video-entity-framework-5-enums-and-moving-solution-from-ef-4-3/和文章http://blogs.msdn.com/b/efdesign/archive/2011/06/29/enumeration-support-in-entity-framework.aspx,它看起來像EF 5處理標誌存儲,但'HasFlag'擴展方法不是但支持。 – Kamyar
@Kamyar'HasFlag'現在支持EF 6.1 – maxp
@maxp yup!感謝RogerAlsing :) – Kamyar