Hi,
I am having a problem with a parent/child relationship whereby the child is not getting persisted by NH and no exception is being thrown.
The parent child relationship is mapped as follows:
Code:
<bag name="Children" table="Child" inverse="true" lazy="true" cascade="all-delete-orphan" order-by="Description">
<cache usage="read-write"/>
<key column="ParentID"/>
<one-to-many class="MyDomain.Parent, MyDomain"/>
</bag>
The Child also has caching enabled in its mapping file:
Code:
<class name="MyDomain.Child, MyDomain" table="Child">
<cache usage="read-write"/>
<property name="ID" type="Int32" not-null="true">
<generator class="identity"/>
</property>
<property name="Description" type="String" length="200" not-null="true"/>
...
The Parent contains the following code to add a new child to the collection:
Code:
public void AddChild(Child child)
{
child.Parent = this;
this.Children.Add(child);
}
The new child persists fine if I remove the cache element on the bag. It also persists fine on all attempts other than the first attempt within a debugging session.
The problem seems like it might be related to lazy loading because if I add breakpoints in my code and inspect the Count or the contents of the bag before the child is added, then the new child gets persisted correctly.
Not sure if this is a bug or something that I am doing wrong.
Any help appreciated.
Thanks,
Jason