Filtering.Net
0.1.2
dotnet add package Filtering.Net --version 0.1.2
NuGet\Install-Package Filtering.Net -Version 0.1.2
<PackageReference Include="Filtering.Net" Version="0.1.2" />
<PackageVersion Include="Filtering.Net" Version="0.1.2" />
<PackageReference Include="Filtering.Net" />
paket add Filtering.Net --version 0.1.2
#r "nuget: Filtering.Net, 0.1.2"
#:package Filtering.Net@0.1.2
#addin nuget:?package=Filtering.Net&version=0.1.2
#tool nuget:?package=Filtering.Net&version=0.1.2
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
FilterRequest—where(FilterNode),sort(SortItem[]),page,pageSize. Polymorphic JSON viaFilterNodeJsonConverter.FilterNode— base;FilterGroup(and/orof children) andFilterLeaf(field+operator+value).SortItem—field+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 byApplywhen validation fails; carries theResultfor HTTP 400 conversion.- Built-in profiles —
StringFilter,BoolFilter,GuidFilter,DateTimeFilter, plusNumeric/*andTemporal/*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
- Documentation site — full guides, API reference, diagnostics catalogue.
- Repo on GitHub — source, issue tracker, contribution notes.
Filtering.Net.Generator— source generator + 24-rule analyzer that emits theIFilterDefinition<T>glue.Filtering.Net.EntityFrameworkCore— asyncApplyPagedAsync+PageResult<T>.- Sample ASP.NET Core 9 + PostgreSQL app:
samples/UserManagement.WebApi/on GitHub.
License
MIT.
| Product | Versions 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. |
-
.NETStandard 2.0
- System.Text.Json (>= 8.0.5)
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.