Pafiso 1.11.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Pafiso --version 1.11.0
                    
NuGet\Install-Package Pafiso -Version 1.11.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="Pafiso" Version="1.11.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pafiso" Version="1.11.0" />
                    
Directory.Packages.props
<PackageReference Include="Pafiso" />
                    
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 Pafiso --version 1.11.0
                    
#r "nuget: Pafiso, 1.11.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.
#:package Pafiso@1.11.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pafiso&version=1.11.0
                    
Install as a Cake Addin
#tool nuget:?package=Pafiso&version=1.11.0
                    
Install as a Cake Tool

Pafiso

A library to serialize, deserialize and apply Paging, Filtering and Sorting.

NuGet Version NuGet Downloads Build Status Deploy Status

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Pafiso:

Package Downloads
Pafiso.AspNetCore

ASP.NET Core integration for Pafiso - provides extensions to construct SearchParameters from query strings

Pafiso.EntityFrameworkCore

Entity Framework Core extensions for Pafiso - provides async query support with IQueryable and EF Core integration

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-beta.1 43 2/13/2026
1.11.0 112 1/23/2026
1.10.1 96 1/23/2026
1.10.0 102 1/22/2026
1.9.1 323 5/8/2025
1.9.0 226 5/8/2025
1.8.3 765 9/22/2022
1.8.2 573 9/22/2022
1.8.1 581 9/22/2022
1.7.0 533 8/18/2022
1.6.0 548 8/11/2022
1.5.0 541 8/10/2022
1.4.1 543 8/5/2022
1.4.0 541 8/4/2022
1.3.1 556 8/4/2022
1.3.0 548 8/4/2022
1.2.6 554 7/27/2022
1.2.5 547 7/27/2022
1.2.4 562 7/27/2022
1.2.3 565 7/27/2022
Loading failed