如何在NHibernate中不重復(fù)加載關(guān)聯(lián)?我需要加載一個(gè)非常大的對象的列表,里面有這么多的孩子和孩子。最好的辦法是什么?我使用的是Oracle 11g數(shù)據(jù)庫,我編寫了以下方法,但結(jié)果是笛卡兒產(chǎn)品(復(fù)制的結(jié)果): 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中不重復(fù)加載關(guān)聯(lián)?
蠱毒傳說
2019-06-29 11:11:10