Hi,
I have a query concerning unsurprisingly NHibernate. The problem is ths.
I have a class named Recipe. A Recipe has a collection of attribues. In my mapping file this is defined as:
Code:
<bag name="Attributes" inverse="false" lazy="true" generic="true" cascade="save-update">
<key column="RecipeUid"/>
<many-to-many class="domain.Attribute, core" column="AttributeId"/>
</bag>
My question is what is the best way of persisting this collection without having to load the many to many class from the database for each attribute?
If I do the following:
Code:
domain.Attribute att = new domain.Attribute(1);
recipe.Attributes.Add(att);
NHibernate thinks that att is a new object and tries to save this instance to the database.
The only way I can get this to work is to load the Attribute object from the database and then add it to the Recipe's attribute collecction and then save it.
This seems inefficient.
Can anyone tell me a better way?
Cheers
Paul