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
<PackageReference Include="Tekulse.Util.SortingAndPaginationHelper" Version="1.0.0" />
<PackageVersion Include="Tekulse.Util.SortingAndPaginationHelper" Version="1.0.0" />
<PackageReference Include="Tekulse.Util.SortingAndPaginationHelper" />
paket add Tekulse.Util.SortingAndPaginationHelper --version 1.0.0
#r "nuget: Tekulse.Util.SortingAndPaginationHelper, 1.0.0"
#addin nuget:?package=Tekulse.Util.SortingAndPaginationHelper&version=1.0.0
#tool nuget:?package=Tekulse.Util.SortingAndPaginationHelper&version=1.0.0
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"
};
- 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:
- Fork the repository.
- Create a new branch (
feature-branch
). - Commit your changes with a meaningful message.
- Push to your fork.
- 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 | Versions 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. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 9.0.3)
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 |