Unwanted fetch with nhibernate API

I am trying to use Api criteria for multiple high-load tables.

My trimmed objects look like this:

class Limit { Risk {get; set;} } class Risk { List<Company> Companies { get;set;} } class Company { List<Address> OldAdresses {get;set;} } class Address { string Street { get;set;} } 

The call to My Criteria is as follows:

 var CriterionGruppe = Expression.Eq("Account.Id", someGuid); var temp = _transaktion.Session.CreateCriteria(typeof(Limit)) .SetFetchMode("Risk", FetchMode.Eager) .SetFetchMode("Risk.Companies", FetchMode.Eager) .Add(CriterionGruppe) .SetResultTransformer(new DistinctRootEntityResultTransformer()) .List<Limit>(); 

Addresses are still loaded by the Select set. How to include old company addresses in my criteria.

I already read the ayende blog post and a few other questions here on stackoverflow. But still no luck.

I hope someone can point me in the right direction.

Thanks in advance peter

When should we use downloads in NHibernate? What is this use?

NHibernate eagerly selects several levels

Ayende Blog

+6
source share
1 answer
 var account = _transaktion.Session.Load<Account>(someGuid); var temp = _transaktion.Session.CreateCriteria(typeof(Limit)) .SetFetchMode("Risk", FetchMode.Eager) .SetFetchMode("Risk.Companies", FetchMode.Eager) .SetFetchMode("Company.OldAddresses", FetchMode.Eager) .Add(Expression.Eq("Account", account)) .SetResultTransformer(new DistinctRootEntityResultTransformer()) .List<Limit>(); 

However, this is very inefficient. You load a huge amount of duplicate data to make a 1 sql query. A better approach would be

  • upload a projection of what is really needed
  • use futures and load a lazy load to avoid a single decibel result set and select n + 1.
+8
source

Source: https://habr.com/ru/post/905709/


All Articles