Skip to content

Instantly share code, notes, and snippets.

@arman-hpp
Created June 24, 2016 06:10
Show Gist options
  • Save arman-hpp/81b3cc2d124a40508c57d7af772769e2 to your computer and use it in GitHub Desktop.
Save arman-hpp/81b3cc2d124a40508c57d7af772769e2 to your computer and use it in GitHub Desktop.
Paging
using System.Linq;
namespace SocialGoal.Data.Infrastructure
{
public class Page
{
public int PageNumber { get; set; }
public int PageSize { get; set; }
public Page()
{
PageNumber = 1;
PageSize = 10;
}
public Page(int pageNumber, int pageSize)
{
PageNumber = pageNumber;
PageSize = pageSize;
}
public int Skip
{
get { return (PageNumber - 1) * PageSize; }
}
}
public static class PagingExtensions
{
/// <summary>
/// Extend IQueryable to simplify access to skip and take methods
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="queryable"></param>
/// <param name="page"></param>
/// <returns>IQueryable with Skip and Take having been performed</returns>
public static IQueryable<T> GetPage<T>(this IQueryable<T> queryable, Page page)
{
return queryable.Skip(page.Skip).Take(page.PageSize);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment