Created
June 24, 2016 06:10
-
-
Save arman-hpp/81b3cc2d124a40508c57d7af772769e2 to your computer and use it in GitHub Desktop.
Paging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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