簡體   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