Path: redb/redb.Examples/ExamplesEf/E194_MinMaxAsyncFiltered_ef.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/ExamplesEf/E194_MinMaxAsyncFiltered_ef.cs
----
using System.Diagnostics;
using Microsoft.EntityFrameworkCore;
using redb.Examples.Ef;
using redb.Examples.Examples;
using redb.Examples.Output;
namespace redb.Examples.ExamplesEf;
/// EF Core twin of : MIN and MAX of Salary in Sales and overall, four queries as in redb.
[ExampleMeta("E194_ef", "EF: MinMaxAsync - With Filter", "Analytics", ExampleTier.Free, 1, "EF", "Min", "Max")]
public class E194_MinMaxAsyncFiltered_ef : EfExampleBase
{
public override async Task RunEfAsync(IDbContextFactory contexts)
{
var sw = Stopwatch.StartNew();
await using var db = await contexts.CreateDbContextAsync();
var sales = db.EmployeeProps.Where(x => x.Department == "Sales");
var minSalary = await sales.MinAsync(x => x.Salary);
var maxSalary = await sales.MaxAsync(x => x.Salary);
var minAll = await db.EmployeeProps.MinAsync(x => x.Salary);
var maxAll = await db.EmployeeProps.MaxAsync(x => x.Salary);
var berlin = db.EmployeeProps.Where(x => x.EmployeeProps_HomeAddress!.City == "Berlin");
var minFloor = await berlin.MinAsync(x => x.EmployeeProps_HomeAddress!.EmployeeProps_HomeAddress_Building!.Floor);
var maxFloor = await berlin.MaxAsync(x => x.EmployeeProps_HomeAddress!.EmployeeProps_HomeAddress_Building!.Floor);
sw.Stop();
return Ok("E194_ef", "EF: MinMaxAsync - With Filter", ExampleTier.Free, sw.ElapsedMilliseconds, 1,
[
$"Sales: {minSalary:N0} - {maxSalary:N0}",
$"All: {minAll:N0} - {maxAll:N0}",
$"Berlin HomeAddress.Building.Floor: {minFloor} - {maxFloor}"
]);
}
}