i am trying to set up a many to many relation ship between "accounts" and "contacts".
My code is saving both the account and the contact object to the database, but it is not making an entry to the join table to maintain the relationship between the 2 objects. I've tried all the combinations of the "inverse" property that exist, as well as a number of other things. I'm at a loss as to why it is not saving the relationship between the two objects. Help is much appreciated.
Executing code
Code:
ISession session = factory.OpenSession();
Account newAccount = new Account();
newAccount.AccountName = accountName.Text;
Contact myContact = new Contact();
myContact.NameFirst = "John";
myContact.NameLast = "Smith";
newAccount.Contacts.Add(myContact);
session.SaveOrUpdate(newAccount);
MappingsCode:
<class name="portal.Account, portal" table="tblAccounts">
<id name="AccountID" column="accountID" >
<generator class="identity" />
</id>
<property name="AccountName" column="accountName" />
<bag name="Contacts" table="tblContactAccountJoin" cascade="save-update" inverse="false" lazy="false">
<key column="accountID" />
<many-to-many column="contactID" class="portal.Contact, portal" />
</bag>
</class>
------------------------------------------------------------------------------
<class name="portal.Contact, portal" table="tblContacts">
<id name="ContactID" column="contactID" unsaved-value="0">
<generator class="identity" />
</id>
<bag name="Accounts" table="tblContactAccountJoin" cascade="save-update" inverse="false" lazy="false">
<key column="contactID" />
<many-to-many column="accountID" class="portal.Account, portal" />
</bag>
<property name="NameFirst" column="nameLast" type="string" length="50" />
<property name="NameLast" column="nameFirst" type="string" length="50" />
<property name="Title" column="title" type="string" length="50" />
</class>