Aggregator
Aggregator is the aggregation function applied inside a GroupBy. Each entry in GroupBy.AggregateBy picks one of the eight functions and a target field — and the result column is named by AggregateBy.Alias.
Values
The two columns at the end tell you whether the function accepts a field at all, and whether that field is constrained to numeric types.
| Value | Description | Supports Field? | Numeric Only? |
|---|---|---|---|
Count | Count items in the group. | Optional — when no field, counts all items in the group. | No |
CountDistinct | Count distinct values of the field. | Required | No |
Sumation | Sum of values. | Required | Yes |
Average | Average of values. | Required | Yes |
Minimum | Minimum value. | Required | No (except Boolean) |
Maximum | Maximum value. | Required | No (except Boolean) |
FirstOrDefault | First value in the group. | Required | No |
LastOrDefault | Last value in the group. | Required | No |
Numeric-only constraints
Sumation and Average only accept numeric fields. Minimum and Maximum reject Boolean fields specifically. Violations throw UnsupportedAggregatorForType(agg, type).Validation rules
| Rule | Error code |
|---|---|
Alias must be non-empty and contain no dots. | InvalidAlias |
Aliases must be unique within an AggregateBy list. | AggregationAliasesMustBeUnique |
An alias cannot match any GroupBy.Fields entry. | AggregationAliasCannotBeGroupByField(alias) |
| Aggregation field must be a simple type (not complex / navigation). | AggregationFieldMustBeSimpleType |
| Aggregation field cannot be a collection. | AggregationFieldCannotBeCollectionType |
Sumation / Average on a non-numeric field. | UnsupportedAggregatorForType(agg, type) |
Minimum / Maximum on a Boolean field. | UnsupportedAggregatorForType(agg, type) |
JSON example
{
"fields": ["Category"],
"aggregateBy": [
{ "field": null, "alias": "TotalCount", "aggregator": "Count" },
{ "field": "Id", "alias": "DistinctIds", "aggregator": "CountDistinct" },
{ "field": "Price", "alias": "TotalRevenue", "aggregator": "Sumation" },
{ "field": "Price", "alias": "AvgPrice", "aggregator": "Average" },
{ "field": "Price", "alias": "MinPrice", "aggregator": "Minimum" },
{ "field": "Price", "alias": "MaxPrice", "aggregator": "Maximum" },
{ "field": "Name", "alias": "FirstName", "aggregator": "FirstOrDefault" },
{ "field": "Name", "alias": "LastName", "aggregator": "LastOrDefault" }
]
}Result (illustrative single group row):
{
"Category": "Electronics",
"TotalCount": 15,
"DistinctIds": 15,
"TotalRevenue": 5249.85,
"AvgPrice": 349.99,
"MinPrice": 9.99,
"MaxPrice": 1299.99,
"FirstName": "Adapter Cable",
"LastName": "Wireless Mouse"
}C# usage
using DynamicWhere.ex.Enums;
var groupBy = new GroupBy
{
Fields = new List<string> { "Category" },
AggregateBy = new List<AggregateBy>
{
new AggregateBy { Field = null, Alias = "TotalCount", Aggregator = Aggregator.Count },
new AggregateBy { Field = "Price", Alias = "TotalRevenue", Aggregator = Aggregator.Sumation },
new AggregateBy { Field = "Price", Alias = "AvgPrice", Aggregator = Aggregator.Average },
}
};Related
- GroupBy → the grouping container that owns the
AggregateBylist. - AggregateBy → a single aggregation entry.
- Summary → wraps grouping with optional having, order, and pagination.
- GroupBy validation → full rule set.