C# 使用IDictionary<;TKey,TValue>;
我正试图用FluentNhibernate映射一个三元关联 我有三张桌子:C# 使用IDictionary<;TKey,TValue>;,c#,.net,nhibernate,fluent-nhibernate,C#,.net,Nhibernate,Fluent Nhibernate,我正试图用FluentNhibernate映射一个三元关联 我有三张桌子: TUser(PK int id,字符串名,…) t组(PK int id,字符串名称,…) TRole(主键int-id,字符串名,…) 第四个关联它们,代表三元关联: TUserGroupRole(FK int userid、FK int groupid、FK int roleid) 基本上,用户对组具有特定的角色。我在模型中使用了3种类型: 用户 UserGroup UserRole 在User类中,我想
TUser(PK int id,字符串名,…)
t组(PK int id,字符串名称,…)
TRole(主键int-id,字符串名,…)
TUserGroupRole(FK int userid、FK int groupid、FK int roleid)
用户
UserGroup
UserRole
User
类中,我想使用IDictionary
按组索引用户角色:
public class User
{
public virtual int Id { get; set; }
public virtual IDictionary<UserGroup, UserRole> Roles { get; set; }
// ...
}
公共类用户
{
公共虚拟整数Id{get;set;}
公共虚拟IDictionary角色{get;set;}
// ...
}
使用常规的hbm格式的XML映射文件,我通过
元素实现了这一点,如(伪映射):
我无法找出如何使用FluentNhibernate生成相同的映射,因此非常感谢您在这一点上提供的任何帮助。对于您在FNH组上得到的回复,请确保您导出的映射文件如下:
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyObject>()
.ExportTo("path")
.Mappings(m=>m.FluentMappings.AddFromAssemblyOf()
.ExportTo(“路径”)
我倾向于同意这种回答,因为我只在元素无序时见过这种类型的异常;也就是当key/index或id元素不是第一个子元素时
HasManyToMany(x => x.Roles)
.ParentKeyColumn("userid")
.AsTernaryAssociation("groupid")
.ChildKeyColumn("roleid");
交叉张贴在
HasManyToMany(x => x.Roles)
.ParentKeyColumn("userid")
.AsTernaryAssociation("groupid")
.ChildKeyColumn("roleid");