NHibernate ThenFetchMany 正在检索重复的孩子 [英] NHibernate ThenFetchMany is retrieving duplicate children

查看:19
本文介绍了NHibernate ThenFetchMany 正在检索重复的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父对象,其子集合包含一个元素,子集合包含一个包含 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?

推荐答案

我能够使用答案 here 使用 QueryOver,它在生成高效 SQL 的同时正确加载对象(选择每个表而不是一个巨大的连接).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆