DynamicWhere.ex
DynamicWhere.exv2.1.0·docs
v2.1.0 released · heterogeneous values, six cache presets

Dynamic LINQ from JSON. For Entity Framework Core.

DynamicWhere.ex is a free, open-source .NET library that turns JSON filter objects into safe, validated, EF Core-native LINQ queries — filter, sort, paginate, project, group, aggregate, and run UNION / INTERSECT / EXCEPT without writing a single expression tree. Works with ASP.NET Core on .NET 6, 7, 8, and 9.

terminal
$ dotnet add package DynamicWhere.ex --version 2.1.0
What's inside

Everything you need to query dynamically

One package. Eleven extension methods. Three composable shapes (Filter, Segment, Summary).

JSON-driven filters

Pass a Condition / ConditionGroup straight from your front-end. No expression trees, no string LINQ.

Sort, page & project

Filter is a single object that wraps where, order, page, and select projection.

GroupBy + aggregations

Sum, Average, Count, Min, Max, FirstOrDefault, LastOrDefault — with optional Having.

Set operations

Union, Intersect, Except across multiple ConditionSets in one Segment query.

Nested navigation

Dotted paths through references and collections — auto-wrapped with .Any() where needed.

Reflection cache

Built-in thread-safe cache with FIFO / LRU / LFU eviction and six tuned presets.

In practice

From front-end JSON to materialized result

Front-end / API bodyJSON
{
  "conditionGroup": {
    "connector": "And",
    "conditions": [
      { "sort": 1, "field": "Price", "dataType": "Number",
        "operator": "GreaterThan", "values": ["50"] },
      { "sort": 2, "field": "Category.Name", "dataType": "Text",
        "operator": "IEqual", "values": ["electronics"] }
    ],
    "subConditionGroups": []
  },
  "selects": ["Id", "Name", "Price", "Category.Name"],
  "orders": [{ "sort": 1, "field": "Price", "direction": "Descending" }],
  "page": { "pageNumber": 1, "pageSize": 10 }
}
Back-end / C# usageC#
using DynamicWhere.ex.Source;
using DynamicWhere.ex.Classes.Complex;
using DynamicWhere.ex.Classes.Core;
using DynamicWhere.ex.Enums;

var filter = new Filter
{
    ConditionGroup = new ConditionGroup
    {
        Connector = Connector.And,
        Conditions = new List<Condition>
        {
            new Condition
            {
                Sort = 1,
                Field = "Name",
                DataType = DataType.Text,
                Operator = Operator.IContains,
                Values = new List<object> { "john" }
            }
        }
    },
    Orders = new List<OrderBy>
    {
        new OrderBy { Sort = 1, Field = "CreatedAt", Direction = Direction.Descending }
    },
    Page = new PageBy { PageNumber = 1, PageSize = 10 }
};

FilterResult<Customer> result = await dbContext.Customers.ToListAsync(filter);
Pick your path

Jump straight to what you need

Frequently asked

DynamicWhere.ex FAQ

Quick answers about dynamic LINQ filters, EF Core support, and JSON query building in .NET.

What is DynamicWhere.ex?+

DynamicWhere.ex is a free, open-source .NET library that turns JSON filter objects into safe, validated, native Entity Framework Core LINQ queries. It handles where, order, paging, projection, group-by, aggregation, having, and UNION / INTERSECT / EXCEPT set operations.

Which .NET and EF Core versions are supported?+

DynamicWhere.ex targets .NET 6, .NET 7, .NET 8, and .NET 9. It works with Entity Framework Core 6+ on any provider that supports IQueryable<T> — SQL Server, PostgreSQL (Npgsql), MySQL (Pomelo), and SQLite are all known to work.

How is DynamicWhere.ex different from System.Linq.Dynamic.Core?+

System.Linq.Dynamic.Core uses string-based predicates. DynamicWhere.ex uses strongly-typed JSON-friendly objects (Condition, ConditionGroup, Filter, Segment, Summary) that are validated, serializable, and safe to expose to your front-end. It also bundles ordering, paging, projection, grouping, aggregation, and set operations in one API.

Is DynamicWhere.ex safe from SQL injection?+

Yes. All filters are parsed into LINQ expression trees and executed through EF Core's parameterized query pipeline. User-supplied field names are validated against the entity type, and operators are restricted to a closed enum.

Can I use DynamicWhere.ex in ASP.NET Core APIs?+

Yes — it is designed for that. Accept a Filter, Segment, or Summary JSON body in your controller, then call .ToListAsync(filter) on any DbSet<T>. The library validates the shape, builds the IQueryable, and returns a strongly-typed result with pagination metadata.

Does DynamicWhere.ex support nested navigation properties?+

Yes. Use dotted field paths like 'Category.Name' or 'Orders.Items.Price'. The library auto-wraps collection traversals with .Any() where needed and validates the path against your entity model.

Is it free?+

Yes. DynamicWhere.ex is licensed under MIT and is free forever for commercial and personal use. The package is published on NuGet.