开发者

NHibernate.Linq to Criteria API translation help needed

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜