I'm using LINQ to NHibernate's IQueryable implementation on a asp.net mvc Grid (telerik specifically), where I know I'll need to fetch something eagerly for this particular grid.
So I have query that looks something like this:
var query = from s in repository.Query<MyClass>()
orderby s.Property.Name, s.Name
select s;
query = query.Fetch(x => x.Property);
Now, if I execute query.ToList(), everything is fine, and I can verify that it works in an integration test.
It's awesome.
However, if I execute query.Count() or something else that aggregates the query, I get an exception:
Query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=0,role=,tableName=[Property],tableAlias=property1,origin=MyClass myclass0_,colums={myclass0_.PropertyGuid ,className=Property}}] [.Count(.Fetch(.ThenBy(.OrderBy(NHibernate.Linq.NhQueryable`1[MyClass], Quote((s, ) => (s.Property.Name)), ), Quote((s, ) => (s.Name)), ), Quote((x, ) => (x.Property)), ), )]
I know that it's trying to tell me that I can't eagerly fetch Property because MyClass isn't in the select, but the problem is that Count() is actually being called via the Grid, and handled externally from my code.
All I'm supposed to need to do is give the grid an IQueryable and it should be able to handle paging, sorting, etc. by itself.
Has anyone else had to get around this issue with NHibernate Fetching and how did you resolve it?