NHibernate version: 1.2.0
Sql Server 2005
This may be a very newbie question. I've googled and googled and found bits a pieces of answers but never a clear answer to this.
I have two tables, fdUser and fdPrinter.
fdUser:
UserID Guid
Name varchar(50)
fdPrinter:
PrinterID Guid
Name varchar(50)
I want to be able to assign any number of printers to a specific user or multiple users so I use an association table called fdUserPrinter. Included with this association is a user specific setting of "DEFAULT" for a given printer associated to the user.
fdUserPrinter:
UserID Guid
PrinterID Guid
Default bit
I have the mapping file for User like this:
Code:
<class name="User" table="fdUser">
<id name="Id" access="nosetter.camelcase-underscore" column="UserID" type="guid" unsaved-value="00000000-0000-0000-0000-0000000000">
<generator class="guid" />
</id>
<property name="Name" type="String" length="50" column="Name" non-null="true" />
<bag name="Printers" cascade="save-update" table="fdUserPrinter">
<key column="UserID" />
<one-to-many class="DomainModel.UserPrinter, DomainModel" not-found="ignore" />
</bag>
</class>
Then I have the mapping file for Printer like this:
Code:
<class name="Printer" table="fdPrinter">
<id name="Id" access="nosetter.camelcase-underscore" column="PrinterID" type="guid" unsaved-value="00000000-0000-0000-0000-0000000000">
<generator class="guid" />
</id>
<property name="Name" type="String" length="50" column="Name" non-null="true" />
<bag name="Users" inverse="true" cascade="save-update" table="fdUserPrinter">
<key column="PrinterID" />
<many-to-many class="DomainModel.User, DomainModel" />
</bag>
</class>
And finally I have my UserPrinter mapped like this:
Code:
<class name="UserPrinter" table="fdUserPrinter">
<composite-id access="field">
<key-property name="UserID" column="UserID" type="Guid" />
<key-property name="PrinterID column="PrinterID" type="Guid" />
</composite-id>
<property name="Default" column="Default" type="boolean" not-null="false" />
</class>
So my question is how can I do the mapping such that the following can be done:
Cascade saving and updating will save the associations
Removing an association from User.Printers collection will delete the association in UserPrinter table
The "Default" value in the UserPrinter class is mapped to the Printer class so I can itterate through User.Printers finding the "Default" printer
I'm somewhat new to NHibernate so I apologize in advance if this is something I should have found in the documentation! :)
Thanks for ANY help with this!