I have this one-to-many association I created zilions of times with 'old' nhibernate or fluent. But I cann't make it work with mapping-by-code
These are the 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 mappings 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 correct INSERT for parent, but it does an UPDATE for any child added
UPDATE TableChildren
......
WHERE Id = 0 <-????
What's am I missing? I'm banging my head!!