【发布时间】:2014-07-08 11:41:15
【问题描述】:
我的问题很简单,并且与另一个问题 (How to map an enum in a one-to-many relationship with NHibernate?) 相关,尽管我在这里专门询问实体框架的流畅 API。
假设(同一个示例)我的模型中有这两个实体,一个引用类型(用户)和另一个枚举(角色)。
class User { int id; IList<Roles> Roles; }
enum Roles { Worker, Manager, Director }
为了清楚起见,或者在这个表示中......
[users] [ roles ]
+-----+ +-------+
| id | |user_id|
+-----+ +-------+
| value | <- [Represented by the enum]
+-------+
现在我想使用 fluent API 将其映射到我在 Entity Framework 中的数据库,但如果我尝试...
HasMany(x => x.Roles)
.Cascade.All()
.Table("UserRoles")
.Element("RolesEnum");
...它将失败,因为HasMany() 不是引用类型。
有没有一种方法可以在不涉及将我的业务模型从枚举更改为类的 fluent API 中执行此操作?
【问题讨论】:
标签: c# entity-framework enums