NHibernate的父母子女保存冗余的SQL更新执行 [英] NHibernate parent-childs save redundant sql update executed
问题描述
我试图用一个子对象集合来保存(插入)父对象,所有的对象都是新的。我更喜欢手动指定要保存更新的内容,以便在自己的映射和刷新会话中不使用任何级联保存。所以基本上我保存这个对象图如下:
session.Save(父)
foreach Childs)
{
session.Save(child);
}
session.Flush()
我希望这段代码插入Parent行,然后每个子行,然而NHibernate执行这个SQL:
插入父项....
INSERT INTO CHILD ....
UPDATE CHILD SET ParentId = @ 1 WHERE Id = @ 2 //如果在之前的查询中设置了ParentId,更新的要点
这个更新语句是绝对不必要的,ParentId已经在INSERT中正确设置了。我如何摆脱它?性能对我来说非常重要。
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 //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.
I forgot "Inverse" in mappings on many-to-one collection.
这篇关于NHibernate的父母子女保存冗余的SQL更新执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!