Pafiso.EntityFrameworkCore
1.11.0
dotnet add package Pafiso.EntityFrameworkCore --version 1.11.0
NuGet\Install-Package Pafiso.EntityFrameworkCore -Version 1.11.0
<PackageReference Include="Pafiso.EntityFrameworkCore" Version="1.11.0" />
<PackageVersion Include="Pafiso.EntityFrameworkCore" Version="1.11.0" />
<PackageReference Include="Pafiso.EntityFrameworkCore" />
paket add Pafiso.EntityFrameworkCore --version 1.11.0
#r "nuget: Pafiso.EntityFrameworkCore, 1.11.0"
#:package Pafiso.EntityFrameworkCore@1.11.0
#addin nuget:?package=Pafiso.EntityFrameworkCore&version=1.11.0
#tool nuget:?package=Pafiso.EntityFrameworkCore&version=1.11.0
Pafiso
A library to serialize, deserialize and apply Paging, Filtering and Sorting.
Installation
Install Pafiso via NuGet Package Manager:
PM> Install-Package Pafiso
Or via the .NET CLI:
dotnet add package Pafiso
Usage
Filtering
Create filters from lambda expressions or manually:
// From expression
var filter = Filter.FromExpression<Product>(x => x.Price > 100);
// Manual creation
var filter = new Filter("Price", FilterOperator.GreaterThan, "100");
// Apply to a query
var results = products.Where(filter);
Supported operators: Equals, NotEquals, GreaterThan, LessThan, GreaterThanOrEquals, LessThanOrEquals, Contains, NotContains, Null, NotNull
Filter across multiple fields (OR condition):
var filter = Filter.FromExpression<Product>(x => x.Name.Contains("phone"))
.AddField(x => x.Description);
// Matches where Name OR Description contains "phone"
var results = products.Where(filter);
Sorting
// From expression
var sorting = Sorting.FromExpression<Product>(x => x.Name, SortOrder.Ascending);
// Manual creation
var sorting = new Sorting("Name", SortOrder.Ascending);
// Apply to a query
var ordered = products.OrderBy(sorting);
// Multiple sort criteria
var ordered = products.OrderBy(firstSorting).ThenBy(secondSorting);
Paging
// From page number and size (0-indexed)
var paging = Paging.FromPaging(page: 0, pageSize: 10);
// From skip/take
var paging = Paging.FromSkipTake(skip: 0, take: 10);
// Apply to a query
var pagedResults = products.Paging(paging);
SearchParameters
Combine filtering, sorting, and paging into a single object:
var searchParams = new SearchParameters(Paging.FromPaging(0, 10))
.AddFilters(Filter.FromExpression<Product>(x => x.Price > 50))
.AddSorting(Sorting.FromExpression<Product>(x => x.Name, SortOrder.Ascending));
// Apply all at once - returns PagedQueryable<T> with TotalEntries
PagedQueryable<Product> result = searchParams.ApplyToIQueryable(products);
Console.WriteLine($"Total: {result.TotalEntries}");
foreach (var product in result) {
Console.WriteLine(product.Name);
}
Serialization
Serialize to dictionary (useful for query strings):
var searchParams = new SearchParameters(Paging.FromPaging(0, 10))
.AddFilters(new Filter("Name", FilterOperator.Contains, "phone"))
.AddSorting(new Sorting("Price", SortOrder.Descending));
IDictionary<string, string> dict = searchParams.ToDictionary();
// Results in: skip=0, take=10, filters[0][fields]=Name, filters[0][op]=Contains, filters[0][val]=phone, ...
// Deserialize back
var restored = SearchParameters.FromDictionary(dict);
ASP.NET Core Integration
Install the ASP.NET Core integration package:
PM> Install-Package Pafiso.AspNetCore
Or via the .NET CLI:
dotnet add package Pafiso.AspNetCore
Parse query parameters from an HTTP request and apply them to a database query:
using Pafiso.AspNetCore;
[HttpGet]
public IActionResult GetProducts()
{
// Convert query string directly to SearchParameters
var searchParams = Request.Query.ToSearchParameters();
// Apply to your IQueryable (e.g., Entity Framework DbSet)
var (countQuery, pagedQuery) = searchParams.ApplyToIQueryable(_dbContext.Products);
return Ok(new {
TotalCount = countQuery.Count(),
Items = pagedQuery.ToList()
});
}
Example query string:
GET /products?skip=0&take=10&filters[0][fields]=Name&filters[0][op]=Contains&filters[0][val]=phone&sortings[0][prop]=Price&sortings[0][ord]=Descending
Field Restrictions
Control which fields can be filtered and sorted by clients using FieldRestrictions:
[HttpGet]
public IActionResult GetProducts()
{
var searchParams = Request.Query.ToSearchParameters();
// Apply with field restrictions
var (countQuery, pagedQuery) = searchParams.ApplyToIQueryable(
_dbContext.Products,
restrictions => restrictions
.AllowFiltering<Product>(x => x.Name, x => x.Price, x => x.Category)
.AllowSorting<Product>(x => x.Name, x => x.Price)
.BlockFiltering<Product>(x => x.InternalCost)
);
return Ok(new {
TotalCount = countQuery.Count(),
Items = pagedQuery.ToList()
});
}
Restriction methods:
AllowFiltering/AllowSorting- Allowlist specific fields (all others are blocked)BlockFiltering/BlockSorting- Blocklist specific fields (all others are allowed)- Blocklist takes precedence over allowlist
- Supports both expression-based (
x => x.Name) and string-based ("Name") field specification
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.2)
- Pafiso (>= 1.11.0)
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.11.0 | 40 | 1/23/2026 |