A lightweight toolkit that extends Entity Framework Core with useful utilities and helpers.
The toolkit provides extension methods for IQueryable to easily add pagination:
- AddPagination: Adds pagination to an IQueryable with required page and size parameters
- AddOptionalPagination: Adds pagination only if valid page and size parameters are provided, otherwise returns all results
Both methods return a PaginatedIEnumerable<T> which includes:
Items: The collection of paginated itemsTotal: The total count of items before pagination
using EntityFrameworkToolKit.Pagination;
// In your data access or service layer:
public async Task<PaginatedIEnumerable<Product>> GetProductsAsync(int page, int pageSize)
{
return await _dbContext.Products
.OrderBy(p => p.Name)
.AddPagination(page, pageSize);
}using EntityFrameworkToolKit.Pagination;
// This will apply pagination only if page and size are valid
// Otherwise returns all products
public async Task<PaginatedIEnumerable<Product>> GetProductsAsync(int? page, int? pageSize)
{
return await _dbContext.Products
.OrderBy(p => p.Name)
.AddOptionalPagination(page, pageSize);
}// In your controller or application layer:
var result = await _productService.GetProductsAsync(page, pageSize);
// Access the paginated items
var products = result.Items;
// Access the total count (useful for UI pagination controls)
var totalCount = result.Total;- .NET 8.0 or higher
- Entity Framework Core 8.0.10 or higher
Contributions are welcome! Please feel free to submit a Pull Request.