.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 : classIEnumerable<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| Parameter | Type | Default | Description |
|---|---|---|---|
filter | Filter | – | Composition object |
getQueryString | bool | false | When true, captures the generated SQL on QueryString |
Pipeline
Whereapplied on the typed query.Counton the typed query →TotalCount.Orderapplied on the typed query.Pageapplied on the typed query.SelectDynamicprojection applied last → produces a dynamicIQueryable.- 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
.ToListAsyncDynamic<T>(Filter)— async EF Core variant..ToList<T>(Filter)— strongly-typed variant..FilterDynamic<T>— non-materializing composition.