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, 9, and 10.
$ dotnet add package DynamicWhere.ex --version 3.4.0Four packages. Twenty-eight extension methods. Three composable shapes (Filter, Segment, Summary), and a policy layer deciding who sees what.
Decide per caller what may be filtered, sorted, selected, grouped and seen. Masking, tokenization and a k-anonymity floor.
Pass a Condition / ConditionGroup straight from your front-end. No expression trees, no string LINQ.
Filter is a single object that wraps where, order, page, and select projection.
Sum, Average, Count, Min, Max, FirstOrDefault, LastOrDefault — with optional Having.
Union, Intersect, Except across multiple ConditionSets in one Segment query.
Dotted paths through references and collections — auto-wrapped with .Any() where needed.
Built-in thread-safe cache with FIFO / LRU / LFU eviction and six tuned presets.
{
"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 }
}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);Quick answers about dynamic LINQ filters, EF Core support, and JSON query building in .NET.
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.
DynamicWhere.ex targets .NET 6, .NET 7, .NET 8, .NET 9, and .NET 10. 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.
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.
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.
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.
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.
Yes, since 3.0. The field-level policy layer decides per caller what may be filtered, sorted, selected, grouped, aggregated and returned. Attributes set the rules in code and an optional store supplies them at runtime without a redeploy. Values can be masked, hashed, tokenized, generalized or replaced on the way out, while filtering and sorting still run against the real value in SQL. It is entirely opt-in: a project that never calls ApplyPolicy behaves exactly as 2.1.5.
Yes. DynamicWhere.ex is licensed under MIT and is free forever for commercial and personal use. The package is published on NuGet.