Мне нужно загрузить список очень больших объектов с таким количеством детей и детей детей. Каков наилучший подход?Как легко загружать ассоциации без дублирования в 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();
}
Возможный дубликат [Как получить отличный результат с NHibernate и QueryOver API?] (HTTP: //stackoverflow.com/questions/4615675/how-to-get-a-distinct-result-with-nhibernate-and-queryover-api) – Sly