开发者

Why Fetch should be the last clause in Linq Nhibernate query

Fetch should be the last clause in Linq based on Mike Hadlow's blog post:

Note that if you want to mix Fetch with other clauses, Fetch must always come last.

So, if Fetch is just indicating the fetch strategy for a property why I cannot have more clauses after Fetch? H

One case that I am facing problem is using AsPagination (MVCContrib) with Fetch. Because AsPagination is trying to get the count on the query that has Fetch by adding .Count() to the end.

So again why the fetch strategy of a property sh开发者_高级运维ould be the last clause in a Linq Nhibernate query statement?


I ran into the same problem before I realized what is going on. http://groups.google.com/group/nhibernate-development/browse_thread/thread/b44957841c9416ba

The most likely reason is it was easier to implement this way because there is no need to account for possible transformations (select/group by) that can happen in the query.

NHibernate has always been difficult in terms of creating paging queries when your entities have associated collections. If you use Criteria or QueryOver, the right way to do this is to have the paging query only return the ids of the entities with a Distinct projection. Those ids would be used in the where condition of the subquery that would contain all the joins.

You can see an example here (the answer):

NHibernate paging criteria with fetchmode eager. (using fluent NH)

I have not tried this technique in Nhibernate LINQ yet but it may work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜