DynamicTableFilter 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package DynamicTableFilter --version 1.0.1
                    
NuGet\Install-Package DynamicTableFilter -Version 1.0.1
                    
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="DynamicTableFilter" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DynamicTableFilter" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="DynamicTableFilter" />
                    
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 DynamicTableFilter --version 1.0.1
                    
#r "nuget: DynamicTableFilter, 1.0.1"
                    
#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 DynamicTableFilter@1.0.1
                    
#: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=DynamicTableFilter&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=DynamicTableFilter&version=1.0.1
                    
Install as a Cake Tool

DynamicTableFilter

NuGet version License: MIT

DynamicTableFilter is a lightweight, powerful, and highly flexible library for EF Core and .NET. It allows you to dynamically apply filtering, sorting, and pagination to any IQueryable<T> data source based on JSON payloads from HTTP requests.

Under the hood, it uses Expression Trees to safely translate user-defined filters directly into highly optimized SQL queries, preventing SQL injection and avoiding performance bottlenecks.


🌟 Features

  • Zero Configuration: Drop it in and it works immediately with your existing Entity Framework Core setup.
  • Dynamic Expression Trees: No hardcoded Where clauses. The library reads the JSON payload and builds the exact SQL needed.
  • Cross-Database Compatible: Works seamlessly with SQL Server, PostgreSQL, MySQL, and SQLite (uses EF.Functions.Like for string matching).
  • Strongly Typed & Safe: Validates property names (DTO projection) before applying filters, throwing clear exceptions if types mismatch.
  • Advanced Filtering: Supports exact matches, range filtering (from/to), IN clauses (arrays), and LIKE string searches.

📦 Installation

(Assuming the package is published to NuGet in the future)

Install via .NET CLI:

dotnet add package DynamicTableFilter

🚀 Quick Start (Backend)

Integrating DynamicTableFilter into your API is incredibly simple. You only need to call .ApplyPageRequest(request) on your IQueryable.

using DynamicTableFilter;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
    private readonly AppDbContext _context;

    public UsersController(AppDbContext context) => _context = context;

    [HttpPost("list")]
    public async Task<IActionResult> GetUsers([FromBody] FilterRequest request)
    {
        // 1. Get base query (Do NOT call .ToList() yet)
        IQueryable<User> query = _context.Users.AsNoTracking();

        // 2. Count total records (before pagination)
        int totalCount = await query.CountAsync();

        // 3. Apply Filters, Sorting, and Pagination dynamically
        query = query.ApplyPageRequest(request);

        // 4. Execute SQL
        var items = await query.ToListAsync();

        // 5. Return Paged Response
        return Ok(new 
        {
            Data = items,
            TotalCount = totalCount,
            PageIndex = request.PageIndex,
            PageSize = request.PageSize
        });
    }
}

💻 Frontend Usage (How to send requests)

The frontend sends a JSON payload to the backend. The library automatically parses this payload and builds the SQL query.

⚠️ CRITICAL NOTE ON PROJECTION: The key in the filter payload must exactly match the property name in the backend C# class (Entity or DTO). It is case-sensitive!

1. Base Payload Structure

{
  "pageIndex": 0,       // 0-based index
  "pageSize": 10,       // Items per page
  "sort": [
    {
      "key": "CreatedAt",
      "value": 1        // 0 = Ascending, 1 = Descending
    }
  ],
  "filter": [
    {
      "key": "Role",
      "value": "Admin"
    }
  ]
}

2. Supported Filter Types

A. String Filtering (Contains)

Translated to SQL LIKE (%value%). Case-insensitive search.

{ "key": "FullName", "value": "john" }
B. Exact Matches (Numbers, Booleans, Enums)

Translates to SQL =.

{ "key": "Age", "value": 30 },
{ "key": "IsActive", "value": true },
{ "key": "Status", "value": 1 }
C. Multiple Values (IN Clause)

Translates to SQL IN (...). Pass an array of values.

{ "key": "DepartmentId", "value": [2, 5, 8] }
D. Range Filters (From / To)

Append .from (>=) or .to (<) to the property key. Perfect for dates and numeric ranges.

{ "key": "Price.from", "value": 100.00 },
{ "key": "Price.to", "value": 500.00 },
{ "key": "CreatedAt.from", "value": "01.01.2024" },
{ "key": "CreatedAt.to", "value": "12.31.2024" }

(Date formats supported by default: MM.dd.yyyy, yyyy-MM-dd, yyyy-MM-ddTHH:mm:ss)

E. Array/Collection Filtering

If the C# property is an array (e.g., public int[] Tags { get; set; }), sending a single value checks if the array contains that value.

{ "key": "Tags", "value": 42 }

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

📝 License

This project is MIT licensed.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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 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
1.1.0 107 10/8/2026
1.0.6 103 10/7/2026
1.0.5 102 10/6/2026
1.0.4 102 10/6/2026
1.0.3 107 10/6/2026
1.0.2 102 10/6/2026
1.0.1 100 10/6/2026
1.0.0 101 10/6/2026