0

我想将以下查询从 nhibernate 标准查询 api 转换为 linq。

 var userquery = session.CreateCriteria(typeof(User))
          .SetFirstResult(pageIndex * pageSize)
          .SetMaxResults(pageSize);

 var totalcountQuery = CriteriaTransformer.Clone(userquery)
           .SetProjection(Projections.RowCountInt64());

谢谢

更新

IEnumerable<User> dbUsers = userquery.Future<User>();
IFutureValue<long> count = totalcountQuery.FutureValue<long>();
4

1 回答 1

1

直接(ish)翻译将是:

var userQuery = session.Query<User>().Skip(pageIndex * pageSize).Take(pageSize);

var totalCount = userQuery.LongCount();

但是,我不确定您为什么要在 Skip & Take 之后进行计数,我想是这样的:

var totalCount = session.Query<User>().LongCount(); 

会更接近你想要的

http://blogs.planetcloud.co.uk/mygreatdiscovery/post/Executing-future-queries-with-NHibernate-Linq.aspx

对于 Linq 上的期货,您可以这样做:

var users = userQuery.ToFuture();    
var totalCount = userQuery.LongCount(); // users will be a future, count won't be but if it's only 2 queries then this will execute them both
于 2012-05-25T12:48:03.983 回答