I have this entity relationship.
public abstract class UserGroup
{
public virtual int UserGroupId { get; set; }
public virtual int GroupType { get; set; }
public virtual string GroupName { get; set; }
public virtual IList<UserGroupMember> GroupMembers { get; set; }
}
public class UserGroupMember
{
public virtual int UserGroupMemberId { get; set; }
public virtual User User { get; set; }
public virtual UserGroup UserGroup { get; set; }
}
Note that UserGroup
is base class and that I have a few derived classes that are discriminated by UserGroup.GroupType
. I am using the Single Table Per Class Hierarchy inheritance mapping strategy.
Fluent NHibernate mappings:
public class UserGroupMap : BaseClassMap<UserGroup>
{
public UserGroupMap()
{
Table("UserGroup");
Id(x => x.UserGroupId);
DiscriminateSubClassesOnColumn("GroupType");
Map(x => x.GroupName);
HasMany(x => x.GroupMembers)
.KeyColumn("UserGroupId")
.Cascade.AllDeleteOrphan()
.Inverse();
}
}
public class UserGroupMemberMap: BaseClassMap<UserGroupMember>
{
public UserGroupMemberMap()
{
Table("UserGroupMember");
Id(x => x.UserGroupMemberId);
References(x => x.User, "UserId")
.Cascade.SaveUpdate();
References(x => x.UserGroup, "UserGroupId")
.Cascade.SaveUpdate();
}
}
This is what I want to achieve:
I would like to make UserGroupMember a base class also and have it discriminate on the UserGroup.GroupType
discriminator. Is this possible?
Another way of wording this question, it would be great if I could add the following line:
DiscriminateSubClassesOnColumn("UserGroup.GroupType");
Into the UserGroupMemberMap