childs save redundant sql update executed
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 saveupdate 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 //What the point of update if ParentId was set in previous query
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.
我在多对一系列的映射中忘记了“反向”。
链接地址: http://www.djcxy.com/p/23240.html下一篇: childs保存执行的冗余sql更新