Path: redb/redb.Examples/Examples/E194_MinMaxAsyncFiltered.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.Examples/Examples/E194_MinMaxAsyncFiltered.cs
----
using System.Diagnostics;
using redb.Core;
using redb.Examples.Models;
using redb.Examples.Output;
namespace redb.Examples.Examples;
///
/// MinAsync/MaxAsync with Where filter applied before aggregation.
/// Filter employees by department, then find salary range.
/// Tests Pro filter handling in single Aggregation.
///
[ExampleMeta("E194", "MinMaxAsync - With Filter", "Analytics",
ExampleTier.Free, 194, "Min", "Max", "Where", "Filter", "Aggregation", RelatedApis = ["IRedbQueryable.MinAsync", "IRedbQueryable.MaxAsync", "IRedbQueryable.Where"])]
public class E194_MinMaxAsyncFiltered : ExampleBase
{
public override async Task RunAsync(IRedbService redb)
{
var sw = Stopwatch.StartNew();
// Salary range for Sales department only
var query = redb.Query()
.Where(x => x.Department == "Sales");
var minSalary = await query.MinAsync(x => x.Salary);
var maxSalary = await query.MaxAsync(x => x.Salary);
// Compare with overall range
var minAll = await redb.Query().MinAsync(x => x.Salary);
var maxAll = await redb.Query().MaxAsync(x => x.Salary);
// Filter and range on nested classes: home city one level deep, floor two levels deep
var berlin = redb.Query()
.Where(x => x.HomeAddress!.City == "Berlin");
var minFloor = await berlin.MinAsync(x => x.HomeAddress!.Building!.Floor);
var maxFloor = await berlin.MaxAsync(x => x.HomeAddress!.Building!.Floor);
sw.Stop();
return Ok("E194", "MinMaxAsync - With Filter", ExampleTier.Free, sw.ElapsedMilliseconds, 1,
[
$"Sales: {minSalary:N0} - {maxSalary:N0}",
$"All: {minAll:N0} - {maxAll:N0}",
$"Berlin HomeAddress.Building.Floor: {minFloor} - {maxFloor}"
]);
}
}