ToPagedList

Paging extension method for NHibernate 3.0 and its new query API QueryOver.

源代码:

1
2
3
4
5
6
7
8
9
10
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);
}
}

示例:

1
2
3
4
5
6
7
8
9
10
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);
}
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×