Path: redb/redb.Examples/Examples/E111_TreeWhereHasDescendant.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/E111_TreeWhereHasDescendant.cs ---- using System.Diagnostics; using redb.Core; using redb.Examples.Models; using redb.Examples.Output; namespace redb.Examples.Examples; /// /// WhereHasDescendant - find parents by child criteria. /// Find offices that have active departments beneath them. /// [ExampleMeta("E111", "Tree Query - WhereHasDescendant", "Trees", ExampleTier.Free, 3, "Tree", "WhereHasDescendant", "Polymorphic", "Pro", Order = 111)] public class E111_TreeWhereHasDescendant : ExampleBase { public override async Task RunAsync(IRedbService redb) { // Find offices that have descendants with Budget > 100000 (decimal test!) var sw = Stopwatch.StartNew(); var offices = await redb.TreeQuery() .Where(d => d.Code.StartsWith("OFF-")) .WhereHasDescendant(desc => desc.Budget > 100000m) .ToListAsync(); sw.Stop(); var codes = offices.Take(5).Select(o => o.Props.Code).ToArray(); return Ok("E111", "Tree Query - WhereHasDescendant", ExampleTier.Free, sw.ElapsedMilliseconds, offices.Count, [ $"Offices with rich descendants (budget > 100k): {offices.Count}", $"Sample: {string.Join(", ", codes)}" ]); } }