DynamicWhere.ex
DynamicWhere.exv2.1.0·docs

.ToListAsyncDynamic<T>(Filter)

Async version of .ToListDynamic<T>(Filter). Uses EF Core's CountAsync() and ToDynamicListAsync() under the hood.

Signature

public static Task<FilterResult<dynamic>> ToListAsyncDynamic<T>(
    this IQueryable<T> query,
    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.
  • CountAsync() on the typed query → TotalCount.
  • Order applied on the typed query.
  • Page applied on the typed query.
  • SelectDynamic projection applied last.
  • ToDynamicListAsync() materializes the result.
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 — see that page for the full set of access patterns through nested dynamic objects and collections.

Returns

Task<FilterResult<dynamic>>.

Example

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

foreach (var p in result.Data)
{
    Console.WriteLine($"{p.Name} — {p.Category.Name}");
}
var result = await dbContext.Products.ToListAsyncDynamic(filter, getQueryString: true);
Console.WriteLine(result.QueryString);
{
  "pageNumber": 1,
  "pageSize": 10,
  "pageCount": 5,
  "totalCount": 42,
  "data": [
    { "Id": 7, "Name": "Laptop Pro", "Price": 1299.99, "Category": { "Name": "Electronics" } }
  ],
  "queryString": null
}

See also