entity framework – 在数据库中保存枚举的ICollection

我有一个类ICollection属性的类。

比如说我们有以下enumeration

 public enum CustomerType { VIP, FrequentCustomer, BadCustomer } 

我们还有以下课程:

 public class Customer { public int Id { get;set; } public string FirstName { get;set; } public string LastName { get;set; } public ICollection CustomerAtrributes { get;set; } } 

如何将属性CustomerAtrributes存储在数据库中以便以后轻松检索?

例如,我正在寻找类似以下的东西:

 CustomerId | FirstName | LastName | CustomerType | 1 | Bob | Smith | VIP | 1 | Bob | Smith | FrequentCustomer| 2 | Mike | Jordan | BadCustomer | 

编辑:我正在使用EntityFramework 6使用CodeFirst方法将我的对象存储在数据库中。

编辑:朋友发现可能重复: ef 5 codefirst枚举集合未在数据库中生成 。但是,如果您有任何不同的想法或变通方法,请发布它们。

枚举仍然是原始类型,特别是整数。 正如您的Costumer类不能将ICollection映射到数据库中的某些内容一样,它也不能包含枚举的集合。

您必须创建一个CostumerType类并重命名枚举:

 public enum TypesOfCostumer //example name { VIP, FrequentCustomer, BadCustomer } public class CostumerType { public int Id { get; set; } public TypesOfCostumer Type {get; set;} }