DynamicWhere.ex
DynamicWhere.exv2.1.0·docs

.ToList<T>(Summary)

Materializes a Summary and returns a SummaryResult with pagination metadata.

IQueryable<T> overload

public static SummaryResult ToList<T>(
    this IQueryable<T> query,
    Summary summary,
    bool getQueryString = false)
    where T : class

IEnumerable<T> overload

In-memory variant for summary operations.

public static SummaryResult ToList<T>(
    this IEnumerable<T> source,
    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.
  • Count on the grouped query → TotalCount.
  • Order applied on the grouped query.
  • Page applied on the grouped query.
  • Materialized as List<dynamic>.
Note
Passing getQueryString: true calls .ToQueryString(), which requires an active EF Core provider; pure in-memory usage may not support it.

Returns

SummaryResult with PageNumber, PageSize, PageCount, TotalCount, Data (List<dynamic> with group keys + aggregation values), and optional QueryString.

Example

SummaryResult result = dbContext.Products.ToList(summary);

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

In-memory variant.

List<Product> source = LoadFromCsv();
SummaryResult result = source.ToList(summary);
{
  "pageNumber": 1,
  "pageSize": 10,
  "pageCount": 1,
  "totalCount": 3,
  "data": [
    { "CategoryName": "Electronics", "ProductCount": 15, "AvgPrice": 349.99, "TotalRevenue": 5249.85 },
    { "CategoryName": "Clothing",    "ProductCount": 12, "AvgPrice": 45.00,  "TotalRevenue": 540.00 }
  ],
  "queryString": null
}
Warning
Dotted GroupBy fields like Category.Name become flattened aliases in the result (e.g., CategoryName).

See also