LinqPaginator

For queries that return a lot of data, a need emerges to consume the results in chunks rather than the entire set. Consuming all results at once can be costly in terms of network traffic thus slowing down your application. Linq Paginator allows you to run your queries and return your data in form of pages. A page contains a set number of items to return per page e.g 20. If for example you have 100 records, it will return the following object: - Page: 1, - TotalPages: 5, - ItemsPerPage: 20, - TotalItems: 100, - Items (collection of the first 20 records)


Keywords
linq, pagination, list, paginator, paging, array, collection
License
MIT
Install
Install-Package LinqPaginator -Version 1.1.0-beta

Documentation

Linq Paginator

Build status Nuget Nuget

Retrieve collection results from IQueryable<T>, IEnumerable<T> or any array based data type that inherits IEnumerable and packages the results into pages for easy fetching to enable lazy loading data on UI components in a fast way when pulling large sets of data.

Install

Install package from Nuget by running the following command in Package Manager Console.

Install-Package LinqPaginator

Then go ahead add a using statement to reference the already downloaded package.

using LinqPaginator;

This library works with almost all arrays that inherit from ICollection<T> and it provides an extension method to paginate your collection as shown below passing a page number and the number of items to return per page.

Sample Data:

IList<string> _names = new List<string>();
_names.Add("Test-01");
_names.Add("Test-02");
_names.Add("Test-03");
_names.Add("Test-04");
_names.Add("Test-05");

Usage

You can use either of the methods.

PagedResult<string> result = _names.Page(page: 1, perpage: 2);
PagedResult<string> result = _names.Paged(page: 1, perpage: 2);
PagedResult<string> result = _names.Paginate(page: 1, perpage: 2);
PagedResult<string> result = _names.ToPages(page: 1, perpage: 2);
PagedResult<string> result = _names.ToPaginate(page: 1, perpage: 2);

Result Model

  • Page : Current Page Number : int
  • ItemsPerPage : Number of items returned in every page : int
  • TotalPages : Total number of pages used to paginate entire collection : int
  • TotalItems : Total number of items matching your pagination request : int
  • Items : Collection containing items in the current page : int