DynamicWhere.ex
DynamicWhere.exv3.4.0·docs

.ToList<T>(Summary)

Materializes a Summary and returns a SummaryResult with pagination metadata.

Guarded, small groups are dropped by default
DwCaps.MinGroupSize ships on, at 5, so a guarded summary removes every group with fewer than five rows — not refused, and nothing in the answer says a group was dropped. That is right for anonymised reporting and surprising for an operational count. Set Caps.MinGroupSize = 1 to switch the floor off, deliberately. An unguarded call is never floored. See k-anonymity.

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> query,
    Summary summary,
    bool getQueryString = false)
    where T : class
ParameterTypeDefaultDescription
summarySummary–Composition 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. On an in-memory source it does not fail — it returns a placeholder sentence where the SQL would be.

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