Tekulse.Util.SortingAndPaginationHelper 1.0.0

dotnet add package Tekulse.Util.SortingAndPaginationHelper --version 1.0.0
                    
NuGet\Install-Package Tekulse.Util.SortingAndPaginationHelper -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tekulse.Util.SortingAndPaginationHelper" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tekulse.Util.SortingAndPaginationHelper" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Tekulse.Util.SortingAndPaginationHelper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tekulse.Util.SortingAndPaginationHelper --version 1.0.0
                    
#r "nuget: Tekulse.Util.SortingAndPaginationHelper, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Tekulse.Util.SortingAndPaginationHelper&version=1.0.0
                    
Install Tekulse.Util.SortingAndPaginationHelper as a Cake Addin
#tool nuget:?package=Tekulse.Util.SortingAndPaginationHelper&version=1.0.0
                    
Install Tekulse.Util.SortingAndPaginationHelper as a Cake Tool

SortingAndPaginationHelper

SortingAndPaginationHelper is a lightweight and efficient .NET library designed to simplify sorting, searching, and pagination for Entity Framework Core (EF Core) queries. This library provides a reusable helper function that dynamically applies sorting, searching, and pagination based on request parameters, making it easy to implement optimized API responses.

πŸš€ Features

βœ… Dynamic Sorting & Pagination – Sort by any column dynamically.
βœ… EF Core Integration – Works seamlessly with IQueryable<T>.
βœ… Search Support – Enables filtering records based on a search term.
βœ… Flexible Sorting Orders – Supports ascending and descending sorting.
βœ… Efficient Pagination – Uses Skip() and Take() for performance optimization.
βœ… Easy to Integrate – Minimal setup required, making it developer-friendly.


πŸ“¦ Installation

Install the NuGet package:

dotnet add package PaginationHelper

Or via the NuGet Package Manager in Visual Studio:

Manage NuGet Packages -> Browse -> Search "PaginationHelper" -> Install

πŸ“– Usage πŸ”Ή 1. Add Pagination & Sorting to a Query Use ApplyListSortingAndPaginationAsync to paginate and sort your data dynamically.

public async Task<ResponseViewModel> GetUsersAsync(ListingParamsViewModel listingParams)
{
    IQueryable<ApplicationUser> userQuery = dbContext.Users;

    // Apply search filtering
    if (!string.IsNullOrEmpty(listingParams.Search))
    {
        userQuery = userQuery.Where(u => u.FirstName.Contains(listingParams.Search)
                                      || u.LastName.Contains(listingParams.Search)
                                      || u.Email.Contains(listingParams.Search));
    }

    // Apply sorting and pagination
    PagedDataViewModel<ApplicationUser> paginatedUsers =
        await paginationHelper.ApplyListSortingAndPaginationAsync(userQuery, listingParams);

    return new ResponseViewModel(StatusCodes.Status200OK, "Users fetched successfully", paginatedUsers);
}

πŸ”Ή 2. Define Pagination and Sorting Parameters Use the ListingParamsViewModel to define page number, page size, sorting column, order, and search filter.

var listingParams = new ListingParamsViewModel
{
    Page = 1,
    PageSize = 10,
    OrderByColumn = "FirstName",
    OrderBy = SortingOrders.Ascending,
    Search = "John"
};
  1. Response Structure The function returns a PagedDataViewModel<T>, containing the paginated records and total record count.
public class PagedDataViewModel<T> where T : class
{
    public List<T> Records { get; set; }
    public int TotalRecords { get; set; }
}

API Integration Example Here’s how you can use PaginationHelper in a .NET API Controller:

[HttpGet("users")]
public async Task<IActionResult> GetUsers([FromQuery] ListingParamsViewModel listingParams)
{
    var response = await _userService.GetUsersAsync(listingParams);
    return Ok(response);
}

πŸ† Why Use PaginationHelper?

βœ… Reduces Boilerplate Code - Eliminates redundant pagination & sorting logic.

βœ… Performance Optimization - Paginates large datasets efficiently using EF Core.

βœ… Highly Maintainable - Centralizes sorting, filtering, and pagination logic.

βœ… Easy to Integrate - Minimal setup required in new or existing projects.

πŸ‘₯ Contributing

Contributions are welcome! Feel free to submit pull requests or report issues.

Steps to Contribute:

  1. Fork the repository.
  2. Create a new branch (feature-branch).
  3. Commit your changes with a meaningful message.
  4. Push to your fork.
  5. Submit a Pull Request (PR) πŸš€.

We appreciate your contributions! πŸŽ‰

πŸ“„ License

This project is licensed under the MIT License.

⭐ Support the Project

If you find this useful, give it a ⭐ star on GitHub!

πŸ”— GitHub Repository: SortingAndPaginationHelper

πŸ“¬ Contact

πŸ“§ Author's Email: abdulrehmanmalikofficial2@gmail.com 🌐 Company Website: Tekulse πŸ“§ Support Email: contact@tekulse.com

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 129 3/19/2025