Fetch/Cacheable Should be Allowed to be Called Anywhere
Description
Environment
Activity
Patrick Earl February 5, 2011 at 2:49 PM
I made the fix suggested by Dean Ward for Cacheable. As far as I can tell, this should all be working now. If there are specific edge cases where there are problems, please file another issue.

Dean Ward February 2, 2011 at 3:18 AM
The Fetch issue should be fixed by https://nhibernate.jira.com/browse/NH-2381#icft=NH-2381 which is in for 3.0.1. Cacheable is a different case, but may be fixed by adding the result operator type to ResultOperatorRewriter::ResultOperatorExpressionRewriter::rewrittenTypes?

Lee Timmins January 14, 2011 at 3:10 AM
Oh right sorry for the confusion.

Richard Brown January 14, 2011 at 3:00 AM
This is not a blocker (NH is working as designed). Vote for the issue to increase it's priority.
NH is working as designed; there are fetching extensions, and the workaround in your case (for now) is to place them last in the expression tree.

Lee Timmins January 14, 2011 at 2:24 AM
I was attempting to write my own patch for this but since Fetch returns INhFetchRequest and not IQueryable it doesn't compile when i add the OrderBy/Where extension methods, for example:
var result = session.Query<Person>()
.Fetch(p => p.Country)
.OrderBy(p => p.Name)
.ToList();
However the title alone explains what the problem is. See the following for other people with the same issue:
http://stackoverflow.com/questions/4165367/nhibernate-linq-eager-load...
http://blogs.planetcloud.co.uk/mygreatdiscovery/post/Eager-loading-wi...
http://stackoverflow.com/questions/4136990/problem-with-linq-to-nhibernate-and-eager-loading-in-mvc-application
http://stackoverflow.com/questions/4363467/using-eager-loading-with-specification-pattern
Details
Details
Assignee
Reporter

When you call Fetch/Cacheable before a Where, OrderBy, Skip, Take etc an exception is thrown. I'm in the process of upgrading an application from the old Linq provider to the one in Nhibernate 3 and this is a major issue for me.
For example I have my own extension method called ToPagedList(1, 15). This converts an IQueryable to a list but applies paging first. The problem is I would need to apply Fetch and/or Cacheable before I convert it to a list but after the Skip/Take which isn't possible without having to re-design my whole application which is not feasible.
I don't know why this should be such an issue, in the old provider it was perfectly fine to call Expand in any position.