Hi,
I’m using a bidirectional many-to-many association in NHibernate. So I’ve got 3 tables named Aanpassing, Module and the table linking both: AanpassingModules.
I created a bag in both Dao’s.
For Module that’s:
Code:
<bag name="Aanpassingen" lazy="true" table="AanpassingModules" inverse="true" fetch="join">
<key column="module" />
<many-to-many class="Cevi.CeXLS.Hibernate.Aanpassing, Cevi.CeXLS.Hibernate" column="aanpassing" />
</bag>
In Aanpassing I’ve got this:
Code:
<bag name="Modules" lazy="true" table="AanpassingModules" fetch="join">
<key column="aanpassing" />
<many-to-many class="Cevi.CeXLS.Hibernate.Module, Cevi.CeXLS.Hibernate" column="module" />
</bag>
Which provides a collection of Modules for each Aanpassing and a collection of Aanpassingen for each Module.
Adding an association works fine, I just do the following:
Code:
anAanpassing.Modules.Add(aModule);
aModule.Aanpassingen.Add(anAanpassing);
And I perform SaveOrUpdate on both Dao’s.
My only problem is deleting an association.
I’ve tried a lot of things, without succes, hopefully someone can help me out. I’ve got this in my code at the moment:
Code:
aModule.Aanpassingen.Remove(anAanpassing);
moddao.SaveOrUpdate(aModule);
moddao.CommitChanges();
anAanpassing.Modules.Remove(aModule);
apdao.SaveOrUpdate(anAanpassing);
apdao.CommitChanges();
thanks in advance![/code]