【发布时间】:2015-06-24 19:24:41
【问题描述】:
我正在使用 Entity Framework Code First 来构建我的数据库。我的类别不经常更改,但将来可能会更改。将类别数据存储在枚举或实际表中会更好吗?下面是我实现这两种方法的示例:
使用枚举:
public enum Role
{
Administrator, Employee, Developer
}
public class User
{
public int ID {get;set;}
public string Name { get; set; }
public Role Role { get; set; }
}
使用单独的表格:
public class User
{
public int ID { get; set; }
public string Name { get; set; }
public int RoleID { get; set; } // Foreign key to Role table
public virtual Role Role { get; set; } // Navigation property for Role
}
public class Role
{
public int ID { get; set; }
public string RoleName { get; set; }
}
【问题讨论】:
标签: c# entity-framework enums