繁体   English   中英

从nhibernate Criteria api到linq的查询

[英]query from nhibernate Criteria api to linq

我想将以下查询从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>();

直接翻译成:

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

var totalCount = userQuery.LongCount();

但是,我不确定您为什么要在“跳过并获取”之后进行计数,我会认为:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM