NHibernate: cannot load download successfully

I am using NH 3.0 and FNH 1.1 recompiled with NH3.

I have a user model where I want to always get her profile at boot time. I am using a linq provider from NH3 but cannot use its Fetch method (due to my repository that hides NHibernate and returns IQueryable, and the fact that ToPagedList is called in the request, so I cannot put Fetch as the last call to the request) .

In UserMap, I installed:

HasOne(x => x.Profile) .Not.LazyLoad() .Cascade.All(); 

But setting LazyLoad to OFF does not help. I also played with the sampling mode.

My expectation is that if I define this mapping, then I don’t even need to tell Linq that I want the profile to be selected when the user object is requested. Linq must comply with cartography, not?

+8
nhibernate fluent-nhibernate linq-to-nhibernate
source share
1 answer

I have this problem too, and unfortunately I think it is by design. The NHibernate 3.0 Linq provider uses HQL under covers, and HQL does not honor your mappings in this regard. For example, if you did

session.CreateQuery ("from profile"). List ()

You would only get a list of all profiles, and your custom class would not join, even if your mapping has external-join = true.

If you used the old NHibernate.Linq provider that used the Critera API or the criteria API directly:

session.CreateCriteria (). List()

You will get a list of all profiles that remain external, connected to users, just like your mapping file.

Now I don’t know why the linq provider supported by HQL does not comply with your mappings (and if anyone knows about this, write), but I believe that is why you see this behavior.

+3
source share

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


All Articles