Do global fetching rules get respected by the LINQ provider in NHibernate 3.0?
I just updated my project to NHibernate 3.0, and I'm trying to convert some of my criteria statements to LINQ statements. Everything seems to be working fine, except that the new LINQ statements don't seem to respect the fetching rules that I declared in my mapping files (using FluentNHibernate).
For example:
public UserMap
{
Id(x => x.Id);
References(x => x.Course).Fetch.Join();
}
Now I query all users like this:
var users = Session.Query<User>().ToList();
I would expect the collection returned to be 开发者_如何学Call the Users in the database with their Course properties eagerly loaded, which is exactly what I'd get when using Criteria statements. But when using the LINQ provider, the query produced by NH does not include the join on the Course table, so all the Courses must be lazily loaded. Is this behavior expected? If so, how can I get NHibernate to respect fetching rules declared in the mappings?
I have the same problem and a similar solution approach with specifications sent to the repository. Each specification has a lamda expression specifying a criteria. The previous Linq provider respected the mappings, why not the new one? Or at least default to the mappings defined with a possibility to override? Is there any way to amend this shortcoming?
No, they don't. You have to specify eager fetching explicitly, using Fetch
/ThenFetch
and FetchMany
/ThenFetchMany
.
精彩评论