ToPagedList
Paging extension method for NHibernate 3.0 and its new query API QueryOver.
Source
public static class QueryOverExtensions
public static PagedList<T> ToPagedList<T>(this IQueryOver<T, T> queryOver, int pageIndex, int pageSize)
{
var rowCountQuery = queryOver.ToRowCountQuery();
IEnumerable<T> list = queryOver.Take(pageSize).Skip((pageIndex - 1) * pageSize).Future();
int totalCount = rowCountQuery.FutureValue<int>().Value;
return new PagedList<T>(list, pageIndex, pageSize, totalCount);
}
}
Example
public class TeamEmployeeRepository : Repository<TeamEmployee>, ITeamEmployeeRepository
{
public PagedList<TeamEmployee> GetPagedEmployees(int pageIndex, int pageSize)
{
return GetSession().QueryOver<TeamEmployee>()
.Fetch(x => x.Employee).Eager
.Fetch(x => x.Team).Eager
.ToPagedList(pageIndex, pageSize);
}
}
Author: Alexander Tank
Submitted on: 1 nov. 2010
Language: C#
Type: Nhibernate.QueryOver
Views: 21238