I'm using NHibernate Conformist mappings. I've already creating some complex mappings using ManyToMany
, OneToMany
, Element
, and Component
relation types for my various collection properties. But I ran into one today that stumped me.
public class Permission
{
public virtual long PermissionId { get; set; }
public virtual string Name { get; set; }
}
public class User
{
...
public virtual Set<string> Permissions { get; set; }
}
public class Group
{
...
public virtual Set<string> Permissions { get; set; }
}
Table Permission
has columns PermissionId
and Name
. Then there is table UserPermission
with columns UserId
and PermissionId
and table GroupPermission
with columns GroupId
and PermissionId
.
As you can see, Permission
is an entity, and there is a many-to-many relationship between users-and-permissions and between groups-and-permissions. However, for purposes of ease of using the User
and Group
objects, I don't want User
and Group
to have a Set<Permission>
(easily accomplished using the ManyToMany
relation type in Conformist). I want to User
and Group
to have a set of permission names. Normally I'd achieve this with the Element
relation type, except for the whole many-to-many-using-join-table problem.
How do I map a collection of simple types that are also many-to-many?