Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion EntityFrameworkPaginate/PaginateService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Data.Entity;

namespace EntityFrameworkPaginate
{
Expand All @@ -16,12 +17,14 @@ public static class PaginateService
/// <returns>A Page object with filtered data for the given page number and page size.</returns>
public static Page<T> Paginate<T>(this IQueryable<T> query, int pageNumber, int pageSize)
{
var pageSkip = (pageNumber - 1) * pageSize;

var result = new Page<T>
{
CurrentPage = pageNumber,
PageSize = pageSize,
RecordCount = query.Count(),
Results = query.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList()
Results = query.Skip(() => pageSkip).Take(() => pageSize).ToList()
};
result.PageCount = (int)Math.Ceiling((double)result.RecordCount / pageSize);
return result;
Expand Down