NHibernate ThenFetchMany正在检索重复的孩子 [英] NHibernate ThenFetchMany is retrieving duplicate children
问题描述
我有一个父对象,其子集合包含一个元素,子集合包含一个孙子"集合,其中包含3个元素.
I have a parent object with a child collection containing one element, the child collection contains a "grandchild" collection containing 3 elements.
我正在使用NHibernate从数据库中加载父对象,如下所示:
I am loading the parent object from the database using NHibernate as follows
Parent parentObject = session.Query<Parent>()
.FetchMany(x => x.Children)
.ThenFetchMany(x => x.GrandChildren)
.Where(x => x.Id = "someparentid")
.Single();
我发现的是,当父对象只有一个时,会有重复的子对象(总共3个)附加到父对象. (每个孩子正确地附加了3个孙对象.)急于加载子对象集合只能正确地工作.
What I'm finding is that there are duplicate children objects (3 in total) attached to the parent object when there should be only one. (There are 3 grandchild objects correctly attached to each child.) Eager loading the children collection only works correctly.
您知道如何在没有重复子对象的情况下实现完整父对象的加载吗?
Do you know how I can achieve loading of the full parent object without duplicate children?
推荐答案
I was able to use the answer here using QueryOver, it correctly loads the objects while generating efficient SQL (selects per table instead of one huge join).
这篇关于NHibernate ThenFetchMany正在检索重复的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!