Filtering.Net 0.1.2

dotnet add package Filtering.Net --version 0.1.2
                    
NuGet\Install-Package Filtering.Net -Version 0.1.2
                    
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="Filtering.Net" Version="0.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Filtering.Net" Version="0.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Filtering.Net" />
                    
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 Filtering.Net --version 0.1.2
                    
#r "nuget: Filtering.Net, 0.1.2"
                    
#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 Filtering.Net@0.1.2
                    
#: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=Filtering.Net&version=0.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Filtering.Net&version=0.1.2
                    
Install as a Cake Tool

Filtering.Net

Type-safe filter / sort / page request types for IQueryable<T>. Pair with Filtering.Net.Generator to get strongly-typed IFilterDefinition<T> implementations generated at compile time, and (optionally) Filtering.Net.EntityFrameworkCore for async EF Core helpers.

What it solves

API consumers post structured JSON — groups of leaves with operators and values — instead of an opaque DSL fragment. Every request is validated before EF Core ever sees it; errors come back as a typed list of FilterValidationErrors with paths and codes. There is no runtime expression-tree construction and no reflection on hot paths: the source generator (separate package) emits one typed predicate per (property, operator) pair.

Install

dotnet add package Filtering.Net
dotnet add package Filtering.Net.Generator   # the source generator (compile-time only)

If you only install Filtering.Net, you get the request types and the IQueryable.Apply extension, but you'll need to write IFilterDefinition<T> implementations by hand. Add the generator package to skip that work.

Quickstart

Declare your entity and a [GenerateFilter<T>] partial:

public sealed class User
{
    public int    Id        { get; set; }
    public string Name      { get; set; } = "";
    public int    Age       { get; set; }
    public bool   IsActive  { get; set; }
}

[GenerateFilter<User>]
public partial class UserFilter
{
    [Map(nameof(User.Id),       Sortable = true)] private static partial void MapId();
    [Map(nameof(User.Name),     Sortable = true)] private static partial void MapName();
    [Map(nameof(User.Age),      Sortable = true)] private static partial void MapAge();
    [Map(nameof(User.IsActive))]                  private static partial void MapIsActive();
}

Apply a request to an IQueryable<User>:

var request = new FilterRequest
{
    Where = new FilterGroup(LogicalOp.And,
    [
        new FilterLeaf("Name",     "contains", "ali"),
        new FilterLeaf("IsActive", "eq",       true),
    ]),
    Sort     = [new SortItem("Age", SortDir.Asc)],
    Page     = 1,
    PageSize = 25,
};

IQueryable<User> result = users.Apply(userFilter, request);

Apply(...) validates first; on failure it throws FilterValidationException whose .Result carries the FilterValidationResult you'd return as HTTP 400.

Key types

  • FilterRequestwhere (FilterNode), sort (SortItem[]), page, pageSize. Polymorphic JSON via FilterNodeJsonConverter.
  • FilterNode — base; FilterGroup (and/or of children) and FilterLeaf (field + operator + value).
  • SortItemfield + dir (Asc / Desc).
  • IFilterDefinition<T> — composite interface every generated filter class implements: Validate(...), ApplyFilter(...), ApplySorting(...).
  • FilterValidationResult / FilterValidationError — structured error shape with JSON-pointer-style paths and codes.
  • FilterValidationException — thrown by Apply when validation fails; carries the Result for HTTP 400 conversion.
  • Built-in profilesStringFilter, BoolFilter, GuidFilter, DateTimeFilter, plus Numeric/* and Temporal/* per primitive. The generator picks one automatically based on the property's CLR type; override with [Map(..., Profile = typeof(MyProfile))].
  • Attributes[GenerateFilter<T>], [Map], [PropertyMap], [FilterProfile<T>], [FilterOperator], [FilterValidator], [InterceptValue], [FilterDefaults], [PageSettings].

Synchronous vs async

IQueryable<T>.Apply(...) is synchronous and returns IQueryable<T> — your call site decides whether to enumerate eagerly (ToList), lazily, or via async EF helpers. For a one-call paged async flow against EF Core, install Filtering.Net.EntityFrameworkCore and use ApplyPagedAsync(...).

See also

License

MIT.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Filtering.Net:

Package Downloads
Filtering.Net.EntityFrameworkCore

Entity Framework Core async helpers for Filtering.Net. One-call filter, sort, and paginate against DbSet, returning a typed PageResult.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.2 112 5/6/2026
0.1.1 105 5/5/2026
0.1.0 112 5/5/2026