DynamicWhere.ex
DynamicWhere.exv2.1.0·docs

.Filter<T>(filter)

Applies a complete Filter (where → order → page → select) to a query.

Signature

public static IQueryable<T> Filter<T>(this IQueryable<T> query, Filter filter)
    where T : class, new()
ParameterTypeDescription
filterFilterComposition object — ConditionGroup, Selects, Orders, Page

Composition order

The pipeline is applied in this order: where → order → page → select.

Warning
Ordering and pagination are applied on the strongly-typed IQueryable<T> before the select 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 .Select<T>.
  • Orders (if provided): each Field must be non-empty and valid on T.
  • Page (if provided): both PageNumber and PageSize must be > 0.
  • Because select uses .Select<T>, T must have a parameterless constructor.

Returns

IQueryable<T> — composed query. You can chain further LINQ operators or call ToList() / ToListAsync() to materialize.

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<Product> query = dbContext.Products.Filter(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