Skip to content

Repository files navigation

EntityFrameworkToolKit

A lightweight toolkit that extends Entity Framework Core with useful utilities and helpers.

Build Status GitHub Package

Features

Pagination

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 items
  • Total: The total count of items before pagination

Usage Examples

Basic 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);
}

Optional Pagination

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);
}

Handling Pagination Results

// 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;

Requirements

  • .NET 8.0 or higher
  • Entity Framework Core 8.0.10 or higher

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

A lightweight toolkit that extends Entity Framework Core with useful utilities and helpers.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages