Relatude Help

27 Aggregates

int count = db.Query<IEvent>().Where(e => e.Status == EventStatus.Published).Count();
int c     = await db.Query<IEvent>().CountAsync();

decimal revenue = db.Query<IEvent>()
                    .WhereRelates(e => e.Venue, venueId)
                    .Sum(e => e.Price);

Count() on the builder answers from the indexes and loads no nodes, so it is much cheaper than Execute().Count(). It returns int; the whole-store counters db.Count() and db.Count<T>() return long.

For an average, a minimum or a maximum, use a pivot with no groups (§28.1). Its grand total holds the measures over every match:

var prices = db.Query<IEvent>().Pivot().AddAverage(e => e.Price).AddMax(e => e.Price).Execute();

double? average = prices.GrandTotal.Get("Price.Average");
double? dearest = prices.GrandTotal.Get("Price.Max");