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();
精彩评论