Hello,
I have a parent/child relationship. And I call session.SaveOrUpdate to save parent. The parent save cascade to the child and saves the child.
Everything was working great, until I did the following:
Create a Parent
Create a child. Add the child to the parent.
SaveOrUpdate(Parent);
It throws an exception: "Cannot insert the value NULL into column 'ParentID' table Child..."
I'm using sqlServer Identity field for my ids. It is as if when the Parent gets insterted the new Id doesn't get reflected in the object. So when I'm trying to save the child it thinks the value is null.
Here is a bunch of snippets.
Class Parent
{
int _parentId;
int ParentId {get{...} set{...}}
IList<Child> _childeren;
IList<Child> Childeren {get{...} set{...}}
}
<class Name=Parent...>
<id name=ParentId>
<generator class="native"/>
</id>
<bag name="Childeren"
inverse="true"
lazy="false"
cascade="all-delete-orphan">
<key column="parentId"/>
<one-to-many class="ChidTable"/>
</bag>
</class>
Class Child
{
int _childId;
Parent _inverseParent;
}
...
Parent p new Parent();
Child c = new Child();
c._inverseParent = p;
p._childeren.Add(c);
SaveOrUpdate(p);
...
Parent is inserted, but when the c is getting inserted I get a
"Cannot insert the value NULL into column 'ParentID'..."
Thanks
|