CaseTunisia.Tools.QueryKit 1.0.1
QueryKit
A lightweight, extensible library for sorting, filtering, and pagination in .NET applications.
Features
- ✅ Attribute-based configuration
- ✅ Multiple filter operators (==, !=, >, <, >=, <=, @=, =, =)
- ✅ Multi-field sorting
- ✅ Built-in pagination
- ✅ Custom filter providers
- ✅ Custom sort providers
- ✅ Entity Framework Core integration
Installation
dotnet add package CaseTunisia.QueryKit
Quick Start
// 1. Decorate your model
public class Product
{
[Sortable, Filterable]
public string Name { get; set; }
[Sortable, Filterable]
public decimal Price { get; set; }
}
// 2. Use in your query
var params = new QueryParameters
{
Filters = "price>100",
Sorts = "-name",
Page = 1,
PageSize = 20
};
var result = dbContext.Products.ToPaginatedList(params);
License
MIT
---
## 🔄 Step 8: Version Updates
When you need to update:
```bash
# Update version in QueryKit.csproj
<Version>1.0.1</Version>
# Build and pack
dotnet build -c Release
dotnet pack -c Release -o ./nupkg
# Push new version
dotnet nuget push ./nupkg/YourCompany.QueryKit.1.0.1.nupkg \
--source "YourCompany" \
--api-key YOUR_API_KEY
🎉 Complete Example in Clean Architecture
// Domain Entity
public class TodoItem
{
[Sortable, Filterable]
public string Title { get; set; }
[Sortable, Filterable]
public bool Done { get; set; }
[Sortable, Filterable]
public int Priority { get; set; }
}
// Application Query
public record GetTodosQuery : IRequest<PaginatedList<TodoDto>>
{
public string Sorts { get; init; }
public string Filters { get; init; }
public int Page { get; init; } = 1;
public int PageSize { get; init; } = 10;
}
// Handler with Custom Provider
public class GetTodosHandler : IRequestHandler<GetTodosQuery, PaginatedList<TodoDto>>
{
private readonly IApplicationDbContext _context;
public async Task<PaginatedList<TodoDto>> Handle(GetTodosQuery request, CancellationToken ct)
{
var processor = new QueryProcessor<TodoItem>()
.AddCustomFilterProvider(new FullTextSearchFilterProvider());
var query = _context.TodoItems.AsQueryable();
var processed = processor.Apply(query, new QueryParameters
{
Sorts = request.Sorts,
Filters = request.Filters,
Page = request.Page,
PageSize = request.PageSize
});
return processor.ApplyPagination(processed, new QueryParameters
{
Page = request.Page,
PageSize = request.PageSize
});
}
}
// API Usage:
// GET /api/todos?filters=search==meeting,done==false&sorts=-priority&page=1
No packages depend on CaseTunisia.Tools.QueryKit.
.NET 8.0
- Microsoft.EntityFrameworkCore (>= 8.0.0)