NHibernate parent-childs save redundant sql update executed
Posted
by
Broken Pipe
on Stack Overflow
See other posts from Stack Overflow
or by Broken Pipe
Published on 2010-12-27T15:52:42Z
Indexed on
2010/12/27
15:53 UTC
Read the original article
Hit count: 281
I'm trying to save (insert) parent object with a collection of child objects, all objects are new. I prefer to manually specify what to save\update and when so I do not use any cascade saves in mappings and flush sessions by myself. So basically I save this object graph like:
session.Save(Parent)
foreach (var child in Parent.Childs)
{
session.Save(child);
}
session.Flush()
I expect this code to insert Parent row, then each child row, however NHibernate executes this SQL:
INSERT INTO PARENT....
INSERT INTO CHILD ....
UPDATE CHILD SET ParentId=@1 WHERE Id=@2
This update statement is absolutely unnecessary, ParentId was already set correctly in INSERT. How do I get rid of it? Performance is very important for me.
© Stack Overflow or respective owner