Mjolnir.Extensions.AspNetCore.Filtering 10.0.5

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

Mjolnir.Extensions.AspNetCore.Filtering

A library for simple entity filtering and sorting in ASP.NET Core projects. It provides extensions for IEnumerable<T> and IQueryable<T> that utilize attributes on property members to define filtering logic.

Features

  • Attribute-Based Filtering: Mark your model properties with attributes like [StringFilter], [RangeFilter<T>], [EnumFilter<T>], [BoolFilter], and [NullFilter].
  • Sorting Support: Use the [Sortable] attribute to enable sorting on specific properties.
  • Custom Filters and Sorting: Extend functionality by implementing your own attributes through [CustomFilter<T>] or [CustomSorting<T>].
  • Works with IEnumerable<T> and IQueryable<T>: Effortlessly filter and sort in-memory collections or database queries.

Installation

Add the library to your project:

dotnet add package Mjolnir.Extensions.AspNetCore.Filtering

Usage

Define Your Model

Apply filtering and sorting attributes to your entity or DTO:

public class Product
{
    public int Id { get; set; }

    [Sortable, StringFilter]
    public string Name { get; set; } = string.Empty;

    [Sortable, RangeFilter<decimal>]
    public decimal Price { get; set; }

    [Sortable, EnumFilter<Category>]
    public Category Category { get; set; }

    [BoolFilter]
    public bool IsActive { get; set; }

    [NullFilter]
    public string? Description { get; set; }
}

public enum Category { Electronics, Clothing, Books }

Apply Filtering and Sorting

Use the FilterBy and SortBy extension methods:

using Mjolnir.Extensions.AspNetCore.Filtering.Extensions;

// Example collections
IEnumerable<Product> products = GetProducts();

// Filter by name (OR logic)
var result = products.FilterBy("Name:Laptop|Book");

// Filter by price range (Min-Max)
result = products.FilterBy("Price:10-100");

// Filter by price range (Unbounded)
result = products.FilterBy("Price:10-*"); // Greater than or equal to 10

// Multiple filters (AND logic)
result = products.FilterBy("Name:Laptop,Price:900-1100");

// Sorting
result = products.SortBy("Price:Asc");
result = products.SortBy("Name:Desc");

Syntax Patterns

Type Pattern Description
Filter Prop:Value Simple match
OR Filter Prop:Val1\|Val2 Matches Val1 OR Val2
Range Filter Prop:Min-Max Matches values between Min and Max (inclusive)
Unbounded Range Prop:0-* Matches values greater than or equal to 0
Sorting Prop:Asc / Prop:Desc Sorts property in given direction
Multiple P1:V1,P2:V2 Applies both filters (AND logic)

Tests

To run the unit tests:

dotnet test Mjolnir.Extensions.AspNetCore.FilteringTest

License

MIT (See root LICENSE 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

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
10.0.5 131 3/25/2026
1.0.0 129 2/25/2026