DynamicWhere.ex
DynamicWhere.exv2.1.0·docs

.ToListDynamic<T>(Filter)

Materializes a Filter using SelectDynamic<T> and returns a FilterResult<dynamic> with pagination metadata. Where and count run on the typed query; ordering, pagination, and projection all happen before materialisation.

IQueryable<T> overload

public static FilterResult<dynamic> ToListDynamic<T>(
    this IQueryable<T> query,
    Filter filter,
    bool getQueryString = false)
    where T : class

IEnumerable<T> overload

In-memory variant — wraps the collection with AsQueryable() then delegates to the IQueryable<T> overload.

public static FilterResult<dynamic> ToListDynamic<T>(
    this IEnumerable<T> source,
    Filter filter,
    bool getQueryString = false)
    where T : class
ParameterTypeDefaultDescription
filterFilterComposition object
getQueryStringboolfalseWhen true, captures the generated SQL on QueryString

Pipeline

  • Where applied on the typed query.
  • Count on the typed query → TotalCount.
  • Order applied on the typed query.
  • Page applied on the typed query.
  • SelectDynamic projection applied last → produces a dynamic IQueryable.
  • Materialized as List<dynamic>.
Warning
Ordering and pagination are applied on the strongly-typed IQueryable<T> before the dynamic projection so that field names referenced in orders always resolve against the original entity type T.
Note
Property names in the dynamic result follow SelectDynamic rules: non-dotted paths are projected as-is; dotted paths through reference navigations produce nested dynamic objects (e.g., result.Category.Name); dotted paths through collection navigations produce nested collections (result.Category.Vendors[0].Id).

Returns

FilterResult<dynamic> — same shape as FilterResult<T> but Data is List<dynamic>.

Example

FilterResult<dynamic> result = dbContext.Products.ToListDynamic(filter);

foreach (var p in result.Data)
{
    // Access nested dynamic object
    Console.WriteLine($"{p.Name} — {p.Category.Name}");
}

In-memory variant.

List<Product> source = LoadFromCsv();
FilterResult<dynamic> result = source.ToListDynamic(filter);
{
  "pageNumber": 1,
  "pageSize": 10,
  "pageCount": 5,
  "totalCount": 42,
  "data": [
    { "Id": 7, "Name": "Laptop Pro", "Price": 1299.99, "Category": { "Name": "Electronics" } }
  ],
  "queryString": null
}

See also