DynamicWhere.ex
DynamicWhere.exv2.1.5·docs

Example 13: Nested Collection Navigation

When a field path traverses a collection property (e.g. Orders.OrderItems.ProductName), the library automatically wraps the inner segment in a .Any() lambda — so the predicate evaluates per-element.

Condition

{
  "sort": 1,
  "field": "Orders.OrderItems.ProductName",
  "dataType": "Text",
  "operator": "IContains",
  "values": ["laptop"]
}

Generated expression

Note
Generated expression:
Orders.Any(i1 => i1.OrderItems.Any(i2 => i2.ProductName != null && i2.ProductName.ToLower().Contains("laptop")))

Each collection segment in the path becomes another nested .Any() level — so deep paths through collections compose cleanly into a single boolean expression EF Core can translate.

Ordering across the same paths

Sorting accepts the same collection paths, but .Any() yields a boolean — useless for ordering. Each collection segment is reduced to one comparable value instead: Min ascending, Max descending.

{
  "sort": 1,
  "field": "Orders.OrderItems.ProductName",
  "direction": "Ascending"
}
Note
Generated expression:
Orders.Min(OrderItems.Min(ProductName)) asc

Rows whose collection is empty sort as null — or as the type default for non-nullable value types, where DefaultIfEmpty() is inserted to keep in-memory sorting from throwing. A path may not end on a collection of entities; sort by a scalar inside it instead (Tags ✗ → Tags.Value ✓).