我有一个具有 type 属性的类ICollection<Enum>
.
比如说我们有以下内容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<CustomerType> 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 枚举集合未在数据库中生成 https://stackoverflow.com/questions/15045303/ef-5-codefirst-enum-collection-not-generated-in-database.但是,如果您有任何不同的想法或解决方法,请发布它们。
枚举仍然是原始类型,特别是整数。正如你的Costumer
类不能有ICollection<int>
映射到数据库中的某些内容,它不能具有枚举的集合。
您必须创建一个 CostumerType 类并重命名枚举:
public enum TypesOfCostumer //example name
{
VIP,
FrequentCustomer,
BadCustomer
}
public class CostumerType
{
public int Id { get; set; }
public TypesOfCostumer Type {get; set;}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)