Using paged queries in the data access layer
In an effort to avoid overwhelming the user and increase application responsiveness, large result sets are commonly broken into smaller pages of results. In this recipe, we'll show you how to easily add paging to a QueryOver
query object in our DAL.
Getting ready
Complete the recipe, Using named queries in the data access layer.
How to do it…
In
Eg.Core.Data.Queries
, add a class using the following code:public class PagedResult<T> { public int TotalCount { get; set; } public IEnumerable<T> Items { get; set; } }
Add an interface using the following code:
public interface IPagedQuery<T> : IQuery<PagedResult<T>> { int PageNumber { get; set; } int PageSize { get; set; } }
In
Eg.Core.Data.Impl.Queries
, add the following class:public abstract class PagedQueryOverBase<T> : NHibernateQueryBase<PagedResult<T>>, IPagedQuery<T> { public PagedQueryOverBase(ISessionFactory sessionFactory...