Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to call IQuerable.ToFuture() and IQuerable.Fetch() in same query for NHibernate (>3.0) Linq?

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

like image 829
Vasea Avatar asked Nov 29 '25 16:11

Vasea


1 Answers

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.

like image 69
Diego Mijelshon Avatar answered Dec 01 '25 11:12

Diego Mijelshon