I have this one-to-many association that I created zilions of times with the old nhibernate or freely. But I can’t get it to work with cartographic code.
These are classes
public class Parent
{
public virtual IList<Child> Children { get; set; }
}
public class Child
{
public virtual Parent Parent { get; set; }
}
Nothing odd
and these are mapping classes
For parent:
Bag(x => x.Parent, m => m.Key(k => k.Column("Parent_id")));
Child:
ManyToOne(x => x.Children, map => { map.Column("Parent_id"); map.Cascade(Cascade.All); });
If I do the following
var parent = new Parent();
parent.Children.Add(new Child());
session.SaveOrUpdate(parent);
I got the correct INSERT for the parent, but it does UPDATE for any child added
UPDATE TableChildren
......
WHERE Id = 0 <-????
What am I missing? I hit my head!
source
share