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类并重命名枚举:
上述就是C#学习教程:entity framework – 在数据库中保存枚举的ICollection分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
public enum TypesOfCostumer //example name { VIP, FrequentCustomer, BadCustomer } public class CostumerType { public int Id { get; set; } public TypesOfCostumer Type {get; set;} }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/955689.html