/// <summary>
/// NHibernate分页实现---条件可变
/// </summary>
/// <param name="maxResults">记录数</param>
/// <param name="pageStart">开始页</param>
/// <param name="totalRecordCount">总记录数</param>
/// <param name="order">排序方式</param>
/// <param name="criterionList">查询条件</param>
/// <returns></returns>
public IList<T> GetByCriteria(int maxResults, int pageStart, out int totalRecordCount, Order order, params ICriterion[] criterionList)
{
ICriteria criteria = CreateCriteria();
foreach (ICriterion criterion in criterionList)
criteria.Add(criterion);
//获取记录总数
ICriteria criteriaRecordCount = CriteriaTransformer.Clone(criteria);
totalRecordCount = criteriaRecordCount.SetProjection(NHibernate.Criterion.Projections.RowCount())
.UniqueResult<int>();
criteria.SetMaxResults(maxResults);
criteria.SetFirstResult(pageStart * maxResults);
if (order != null)
criteria.AddOrder(order);
return criteria.List<T>();
}
/// NHibernate分页实现---条件可变
/// </summary>
/// <param name="maxResults">记录数</param>
/// <param name="pageStart">开始页</param>
/// <param name="totalRecordCount">总记录数</param>
/// <param name="order">排序方式</param>
/// <param name="criterionList">查询条件</param>
/// <returns></returns>
public IList<T> GetByCriteria(int maxResults, int pageStart, out int totalRecordCount, Order order, params ICriterion[] criterionList)
{
ICriteria criteria = CreateCriteria();
foreach (ICriterion criterion in criterionList)
criteria.Add(criterion);
//获取记录总数
ICriteria criteriaRecordCount = CriteriaTransformer.Clone(criteria);
totalRecordCount = criteriaRecordCount.SetProjection(NHibernate.Criterion.Projections.RowCount())
.UniqueResult<int>();
criteria.SetMaxResults(maxResults);
criteria.SetFirstResult(pageStart * maxResults);
if (order != null)
criteria.AddOrder(order);
return criteria.List<T>();
}