I am trying to create a many-to-many association between two child objects.
I have an Application Class which represents the applications available in the system
Application has a many-to-many relationship to the UserRoles Class
Application has a one-to-many relationship to the ApplicationFunctions class
An Application can be related to many UserRoles and UserRoles can be Related to many Applications.
An Application can have many ApplicationFunctions, each ApplicaitonFunction is related to only one Application.
The UserRoles that are related to a particular application can only have an association to the ApplicationFunctions that are related to that application.
I've been trying to use the mapping association show in the Nhibernate in Action book in chapter 8 on pages 193 - 199. But have not had any luck getting it to work.
This mapping currently produces duplicates and doesn't limit the UserRole -> ApplictionFunction relatationship to the current Application
<bag name="_roleFunctions" lazy="true" table="UserRoleFunctions" access="field" cascade="all-delete-orphan, save-update">
<key column="UserRoleId" />
<many-to-many column="FunctionID" class="myspace.AppName.Domain.ApplicationFunction, myspace.AppName.Domain"/>
</bag>
This mapping using a new UserRoleFunctions Class does not produce any entries in the UserRoleFunctions table:
<bag name="_userRoleFunctions" lazy="true" table="UserRoleFunctions" access="field" cascade="all-delete-orphan, save-update">
<key column="UserRoleId" />
<composite-element class="myspace.AppName.Domain.UserRoleFunctions, myspace.AppName.Domain" >
<parent name="UserRole"/>
<many-to-one name="_applicationFunctions"
class="myspace.AppName.Domain.ApplicationFunction, myspace.AppName.Domain"
column="FunctionID" not-null="true" access="field" cascade="all-delete-orphan, save-update"/>
<property name="ApplicationDefinition" type="guid" column="ApplicationID" not-null="true" />
</composite-element>
</bag>