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 N开发者_JAVA百科hFetchRequest 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
It's a bug/unsupported scenario. The error message is misleading.
You can open an issue at htt://jira.nhforge.org
The problem is with the fetch; it's not related to the FutureValue part.
精彩评论