StellarPageable is a lightweight C# library designed to simplify filtering, ordering, and paginating data from an IQueryable
source. This library is ideal for use with Entity Framework Core and provides an efficient way to handle paginated API responses.
- Dynamic Filtering: Apply multiple filters with simple syntax.
- Dynamic Ordering: Easily sort data by any property.
- Pagination: Effortlessly paginate large datasets with customizable page size and number.
- Asynchronous Execution: Optimized for scalability with async methods.
- Error Handling: Descriptive error messages for invalid inputs.
- Clone or download the repository.
- Add the project reference to your solution.
- Alternatively, you can compile it into a DLL and include it in your project.
Note: NuGet package support coming soon!
Add the following model classes to your project if they are not already included:
public class PaginatedRequest
{
public int PageNumber { get; set; } = 1;
public int PageSize { get; set; } = 10;
public string? Filter { get; set; } // Example: "Name eq 'John'; Age gt 25"
public string? OrderBy { get; set; } // Example: "Name desc"
}
public class PaginatedResponse<T>
{
public List<T> Data { get; set; }
public int TotalRecords { get; set; }
public int TotalPages { get; set; }
public int PageNumber { get; set; }
public int PageSize { get; set; }
}
Use the extension method to retrieve paginated data from your IQueryable
source:
var paginatedResult = await dbContext.YourEntity
.GetPaginatedAsync(new PaginatedRequest
{
PageNumber = 1,
PageSize = 10,
OrderBy = "Name desc",
Filter = "Age gt 30; Name eq 'John'"
});
The GetPaginatedAsync
method will return a PaginatedResponse<T>
with the following fields:
- Data: The list of items for the current page.
- TotalRecords: Total number of records in the dataset.
- TotalPages: Total number of pages available.
- PageNumber: Current page number.
- PageSize: Number of items per page.
Here's a simple example to integrate StellarPageable with an API endpoint:
[HttpGet]
public async Task<IActionResult> GetUsers([FromQuery] PaginatedRequest request)
{
var paginatedUsers = await _dbContext.Users.GetPaginatedAsync(request);
return Ok(paginatedUsers);
}
- NuGet package support.
- Support for Dapper and other ORMs.
- Additional filtering options for advanced scenarios.
For questions or feedback, feel free to reach out:
- Email: [email protected]
- Instagram: @raj__rr
This project is licensed under the MIT License. See the LICENSE
file for details.