亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在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條經驗 獲得超13個贊

只要你急于加載多個集合,那么笛卡爾產品就會出現。為了選擇合適的批次大小,我可能會選擇與page size因為感覺很好.。(但沒有證據)

然而,無論你走哪條路,我建議你向結果扔一個分析器,看看哪個對你有更好的效果.


查看完整回答
反對 回復 2019-06-29
  • 2 回答
  • 0 關注
  • 561 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號