开发者

NHibernate.Linq to Criteria API translation help needed

开发者 https://www.devze.com 2022-12-23 09:34 出处:网络
I\'m not sure how to add paging to this: Session.Linq<Article>() .Where(art => 开发者_运维技巧art.Tags.Any(t => t.Name == tag)).ToList().

I'm not sure how to add paging to this:

Session.Linq<Article>()
  .Where(art => 开发者_运维技巧art.Tags.Any(t => t.Name == tag)).ToList().

So i decided to use Criteria API.

var rowCount = Session.CreateCriteria(typeof(Article))
  .SetProjection(Projections.RowCount()).FutureValue<Int32>();

var res = Session.CreateCriteria(typeof(Article))
  .Add(/* any help with this? :) */)
  .SetFirstResult(page * pageSize)
  .SetMaxResults(pageSize)    
  .AddOrder(new Order("DatePublish", true))
  .Future<Article>();

totalCount = rowCount.Value;

Any help appreciated.


In link to do paging you use the commands Skip and Take.

Your scenario:

Session.Linq<Article>()
  .Where(art => art.Tags.Any(t => t.Name == tag))
  .Skip(2*20).Take(20)
  .ToList();

int totalCount = Session.Linq<Article>()
                     .Where(art => art.Tags.Any(t => t.Name == tag))
                     .Count();
0

精彩评论

暂无评论...
验证码 换一张
取 消