I'm trying to map a ternary association using FluentNhibernate.
I have 3 tables:
TUser(PK int id, string name, ...)
TGroup(PK int id, string name, ...)
TRole(PK int id, string name, ...)
And a 4th one that associates them, representing the ternary association:
TUserGroupRole(FK int userid, FK int groupid, FK int roleid)
Basically, a user has a particular role for a group. I'm using 3 types in my model :
User
UserGroup
UserRole
In the User
class, I want to use an IDictionary<UserGroup,UserRole>
to index user roles by groups:
public class User
{
public virtual int Id { get; set; }
public virtual IDictionary<UserGroup, UserRole> Roles { get; set; }
// ...
}
Using regular hbm fashioned XML mapping file, I achieved that with a <map>
element, like so (pseudo mapping):
<map name="Roles" table="TUserGroupRole">
<key column="userid"/>
<index-many-to-many column="groupid" class="UserGroup"/>
<many-to-many column="roleid" class="UserRole"/>
</map>
I wasn't able to figure out how to generate the same mapping using FluentNhibernate, so any help on this point would be very appreciated.