I have thw following legacy code and since we use the JetDriver we cannot use the CreateMultiCriteria:
public static PagedList<T> PagedList<T>(this ICriteria criteria, ISession session, int pageIndex, int pageSize) where T : class
{
if (pageIndex < 0) pageIndex = 0;
/* // Old Code
var countCrit = (ICriteria)criteria.Clone();
countCrit.ClearOrders();
var results = session.CreateMultiCriteria()
.Add<long>(countCrit.SetProjection(Projections.RowCountInt64()))
.Add<T>(criteria.SetFirstResult(pageIndex * pageSize).SetMaxResults(pageSize))
.List();
var totalCount = ((IList<long>)results[0])[0];
return new PagedList<T>((IList<T>)results[1], totalCount, pageIndex, pageSize);
*/
// New Code
var queryOver = session.QueryOver<T>();
IEnumerable<T> list = queryOver.Take(pageSize).Skip(pageIndex * pageSize).Future();
int totalCount = queryOver.ToRowCountQuery().FutureValue<int>().Value;
return new PagedList<T>(list.ToList(), totalCount, pageIndex, pageSize);
}
So we rewritten the code and it works but I dunno how to reuse the criteria parameters as we did in the old code. Any hints?
I would like to apply the criteria