为了账号安全,请及时绑定邮箱和手机立即绑定

如何在NHibernate中不重复加载关联?

如何在NHibernate中不重复加载关联?

如何在NHibernate中不重复加载关联?我需要加载一个非常大的对象的列表,里面有这么多的孩子和孩子。最好的办法是什么?我使用的是Oracle 11g数据库,我编写了以下方法,但结果是笛卡儿产品(复制的结果): public IList<ARNomination> GetByEventId(long eventId)         {             var session = this._sessionFactory.Session;             var nominationQuery = session.Query<ARNomination>().Where(n => n.Event.Id == eventId);             using (var trans = session.Transaction)             {                 trans.Begin();                 // this will load the Contacts in one statement                 nominationQuery                    .FetchMany(n => n.Contacts)                     .ToFuture();                 // this will load the CustomAttributes in one statement                 nominationQuery                    .FetchMany(n => n.CustomAttributes)                     .ToFuture();                 // this will load the nominations but joins those two tables in one statement which results in cartesian product                 nominationQuery                    .FetchMany(n => n.CustomAttributes)                     .FetchMany(n => n.Contacts)                     .ToFuture();                 trans.Commit();             }             return nominationQuery.ToList();         }
查看完整描述

2 回答

?
开心每一天1111

TA贡献1836条经验 获得超12个赞

只要你急于加载多个集合,那么笛卡尔产品就会出现。为了选择合适的批次大小,我可能会选择与page size因为感觉很好.。(但没有证据)

然而,无论你走哪条路,我建议你向结果扔一个分析器,看看哪个对你有更好的效果.


查看完整回答
反对 回复 2019-06-29
  • 2 回答
  • 0 关注
  • 497 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信