Path: redb/redb.Core/Query/Aggregation/Agg.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Query/Aggregation/Agg.cs ---- namespace redb.Core.Query.Aggregation; /// /// Static helper for creating aggregate expressions in Select /// Allows writing: .Select(x => new { Total = Agg.Sum(x.Props.Price) }) /// public static class Agg { /// /// Sum of field values /// /// /// .Select(x => new { Total = Agg.Sum(x.Props.Price) }) /// .Select(x => new { ItemsTotal = Agg.Sum(x.Props.Items.Select(i => i.Price)) }) /// public static decimal Sum(decimal value) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static decimal Sum(decimal? value) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static long Sum(long value) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static long Sum(long? value) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static int Sum(int value) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static int Sum(int? value) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static double Sum(double value) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static double Sum(double? value) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); /// /// Sum of values from a collection (for arrays) /// public static decimal Sum(IEnumerable values) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static decimal Sum(IEnumerable values) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static long Sum(IEnumerable values) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static int Sum(IEnumerable values) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); public static double Sum(IEnumerable values) => throw new NotSupportedException("Agg.Sum must be processed in ProjectionFieldExtractor"); /// /// Average value of a field /// public static decimal Average(decimal value) => throw new NotSupportedException("Agg.Average must be processed in ProjectionFieldExtractor"); public static decimal Average(decimal? value) => throw new NotSupportedException("Agg.Average must be processed in ProjectionFieldExtractor"); public static double Average(long value) => throw new NotSupportedException("Agg.Average must be processed in ProjectionFieldExtractor"); public static double Average(int value) => throw new NotSupportedException("Agg.Average must be processed in ProjectionFieldExtractor"); public static double Average(double value) => throw new NotSupportedException("Agg.Average must be processed in ProjectionFieldExtractor"); /// /// Average value from a collection (for arrays) /// public static decimal Average(IEnumerable values) => throw new NotSupportedException("Agg.Average must be processed in ProjectionFieldExtractor"); public static double Average(IEnumerable values) => throw new NotSupportedException("Agg.Average must be processed in ProjectionFieldExtractor"); public static double Average(IEnumerable values) => throw new NotSupportedException("Agg.Average must be processed in ProjectionFieldExtractor"); public static double Average(IEnumerable values) => throw new NotSupportedException("Agg.Average must be processed in ProjectionFieldExtractor"); /// /// Minimum value of a field /// public static T Min(T value) => throw new NotSupportedException("Agg.Min must be processed in ProjectionFieldExtractor"); /// /// Minimum value from a collection /// public static T Min(IEnumerable values) => throw new NotSupportedException("Agg.Min must be processed in ProjectionFieldExtractor"); /// /// Maximum value of a field /// public static T Max(T value) => throw new NotSupportedException("Agg.Max must be processed in ProjectionFieldExtractor"); /// /// Maximum value from a collection /// public static T Max(IEnumerable values) => throw new NotSupportedException("Agg.Max must be processed in ProjectionFieldExtractor"); /// /// Count of elements in a collection /// public static int Count(IEnumerable values) => throw new NotSupportedException("Agg.Count must be processed in ProjectionFieldExtractor"); /// /// Count of records (COUNT(*)) /// public static int Count() => throw new NotSupportedException("Agg.Count must be processed in AggregateAsync"); // ===== GROUPBY OVERLOADS ===== /// /// Sum in a group: Agg.Sum(g, x => x.Stock) /// public static TValue Sum(Grouping.IRedbGrouping group, System.Linq.Expressions.Expression> selector) => throw new NotSupportedException("Agg.Sum for GroupBy"); /// /// Average in a group: Agg.Average(g, x => x.Age) /// public static double Average(Grouping.IRedbGrouping group, System.Linq.Expressions.Expression> selector) => throw new NotSupportedException("Agg.Average for GroupBy"); /// /// Minimum in a group: Agg.Min(g, x => x.Price) /// public static TValue Min(Grouping.IRedbGrouping group, System.Linq.Expressions.Expression> selector) => throw new NotSupportedException("Agg.Min for GroupBy"); /// /// Maximum in a group: Agg.Max(g, x => x.Price) /// public static TValue Max(Grouping.IRedbGrouping group, System.Linq.Expressions.Expression> selector) => throw new NotSupportedException("Agg.Max for GroupBy"); /// /// Count in a group: Agg.Count(g) /// public static int Count(Grouping.IRedbGrouping group) => throw new NotSupportedException("Agg.Count for GroupBy"); /// /// Count of the members of a group that satisfy a condition: Agg.Count(g, c => c.IsVerified). /// Works in SelectAsync and in Having, for GroupBy, GroupByArray and their tree forms. The condition may /// compare fields with constants or with each other, combine comparisons with &&, || and !, test a /// field for null and use a boolean field alone. /// public static int Count( Grouping.IRedbGrouping group, System.Linq.Expressions.Expression> predicate) => throw new NotSupportedException("Agg.Count for GroupBy"); }