【发布时间】:2014-01-25 01:54:36
【问题描述】:
我需要加载一个包含这么多孩子和孩子的孩子的非常大的对象的列表。最好的方法是什么?
我使用的是 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();
}
【问题讨论】:
标签: nhibernate orm future eager-loading cartesian-product