I want to use LINQ to NHibernate for a classic counting/pagination scenario:
var query = Session.Query<Entity>().Where(...);
var count = query.ToFutureValue(c => c.Count());
var results = query.OrderBy(x => x.Field)
.Skip(20)
.Take(10)
.Fetch(x => x.Related1)
.Fetch(x => x.Related2)
.ToFuture();
The core implementation of ToFutureValue() doesn't take an expression parameter, however this is very simple to implement (explained in this blog post). The last query fails with NotSupportedException("You can also use the AsFuture() method on NhQueryable") when calling .ToFuture() method. The problem seems to be that .Fetch() extension method returns an NhFetchRequest and the .Future() extension method expects and NhQuerable. Is there any workaround to this?
Edit: This bug was fixed in NHibernate Linq provider as of version 3.2