.FilterDynamic<T>(filter)
Applies a complete Filter (where → order → page → dynamic select) to a query and returns a dynamic IQueryable.
Signature
public static IQueryable FilterDynamic<T>(this IQueryable<T> query, Filter filter)
where T : class| Parameter | Type | Description |
|---|---|---|
filter | Filter | Composition object — ConditionGroup, Selects, Orders, Page |
Composition order
The pipeline is applied in this order: where → order → page → dynamic select.
Warning
Ordering and pagination are applied on the strongly-typed
IQueryable<T> before the dynamic projection so that original field names referenced in orders always resolve against the original entity type T, regardless of which fields are projected.Validations
ConditionGroup(if provided) is validated as in.Where<T>.Selects(if provided) is validated as in.SelectDynamic<T>.Orders(if provided): eachFieldmust be non-empty and valid onT.Page(if provided): bothPageNumberandPageSizemust be > 0.
Note
Unlike
.Filter<T>, this method does not require a parameterless constructor on T.Returns
IQueryable — dynamic composed query whose elements are anonymous objects. Projection rules follow SelectDynamic — non-dotted paths are projected as-is (whole object or collection); dotted paths through reference navigations produce nested dynamic objects (Category: { Name: "..." }); dotted paths through collection navigations use Select lambdas to project individual element fields (Category: { Vendors: [{ Id: … }] }).
Example
var filter = new Filter
{
ConditionGroup = new ConditionGroup
{
Connector = Connector.And,
Conditions = new List<Condition>
{
new Condition { Sort = 1, Field = "Price", DataType = DataType.Number, Operator = Operator.GreaterThan, Values = new List<object> { 50 } },
new Condition { Sort = 2, Field = "Category.Name", DataType = DataType.Text, Operator = Operator.IEqual, Values = new List<object> { "electronics" } }
}
},
Selects = new List<string> { "Id", "Name", "Price", "Category.Name" },
Orders = new List<OrderBy> { new OrderBy { Sort = 1, Field = "Price", Direction = Direction.Descending } },
Page = new PageBy { PageNumber = 1, PageSize = 10 }
};
IQueryable query = dbContext.Products.FilterDynamic(filter);{
"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 }
}See also
.Filter<T>— strongly-typed variant..ToListDynamic<T>(Filter)/.ToListAsyncDynamic<T>(Filter)to materialize.- JSON Cookbook: FilterDynamic.