I'm using NH 3.0 and FNH 1.1 recompiled with NH3.
I have a user model where I want to always retrieve its profile when loading it. I use the linq provider from NH3 but can't use its Fetch method (because of my repository that hides NHibernate and returns an IQueryable and the fact that ToPagedList is called on the query therefore preventing me to put Fetch as the last call of the query).
In the UserMap I set:
HasOne(x => x.Profile)
.Not.LazyLoad()
.Cascade.All();
But setting LazyLoad to OFF does not help. I played with the fetch mode too.
My expectation is that if I define this mapping, then I should not even have to tell Linq that I want Profile to be fetched when the User entity is requested. Linq should honour the mapping, no?
I am having this problem as well, and unfortunately I think it is by design. The NHibernate 3.0 Linq provider uses HQL under the covers, and HQL doesn't honor your mappings in this respect. For example, if you did
session.CreateQuery("from Profile").List()
You would only get a list of all profiles and your user class would not join even if your mapping has outer-join=true.
If you were using the old NHibernate.Linq provider that used the Critera API, or the Criteria API directly:
session.CreateCriteria().List()
you would get back a list of all profiles left outer joined with users, just as your mapping file requested.
Now I don't know why the HQL backed linq provider doesn't honor your mappings (and if anyone knows a way around this, please post), but I believe that is why you are seeing this behavior.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With