DynamicWhere.ex
DynamicWhere.exv2.1.0·docs

.ToListAsync<T>(Summary)

Async version of .ToList<T>(Summary). Uses EF Core's async count/materialization under the hood.

Signature

public static Task<SummaryResult> ToListAsync<T>(
    this IQueryable<T> query,
    Summary summary,
    bool getQueryString = false)
    where T : class
ParameterTypeDefaultDescription
summarySummaryComposition object
getQueryStringboolfalseWhen true, captures the generated SQL on SummaryResult.QueryString

Pipeline

  • Where applied on the typed query.
  • Group applied — produces grouped dynamic intermediate.
  • Having applied — fields must reference aggregate aliases.
  • Async count on the grouped query → TotalCount.
  • Order applied on the grouped query.
  • Page applied on the grouped query.
  • Async materialization as List<dynamic>.
Note
Dotted GroupBy fields like Category.Name become flattened aliases in the result (e.g., CategoryName). Order fields in Summary.Orders use the dotted form — the library handles alias mapping internally.

Returns

Task<SummaryResult>.

Example

SummaryResult result = await dbContext.Products.ToListAsync(summary);

foreach (var row in result.Data)
{
    Console.WriteLine($"{row.CategoryName}: {row.ProductCount} products");
}

ASP.NET Core endpoint.

app.MapPost("/products/summary", async (Summary summary, AppDbContext db) =>
{
    var result = await db.Products.ToListAsync(summary);
    return Results.Ok(result);
});
{
  "pageNumber": 1,
  "pageSize": 10,
  "pageCount": 1,
  "totalCount": 3,
  "data": [
    { "CategoryName": "Electronics", "ProductCount": 15, "AvgPrice": 349.99, "TotalRevenue": 5249.85 }
  ],
  "queryString": null
}

See also