Path: redb/redb.Examples/Examples/E110_TreeWhereHasAncestor.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/E110_TreeWhereHasAncestor.cs ---- using System.Diagnostics; using redb.Core; using redb.Examples.Models; using redb.Examples.Output; namespace redb.Examples.Examples; /// /// WhereHasAncestor - polymorphic ancestor filter. /// Find nodes that have a specific type of ancestor matching condition. /// [ExampleMeta("E110", "Tree Query - WhereHasAncestor", "Trees", ExampleTier.Free, 3, "Tree", "WhereHasAncestor", "Polymorphic", "Pro", Order = 110, RelatedApis = ["ITreeQueryable.WhereHasAncestor"])] public class E110_TreeWhereHasAncestor : ExampleBase { public override async Task RunAsync(IRedbService redb) { // Find teams that have an ancestor with Budget > 500000 (decimal test!) var sw = Stopwatch.StartNew(); var teams = await redb.TreeQuery() .Where(d => d.Code.StartsWith("TEAM-")) .WhereHasAncestor(anc => anc.Budget > 500000m) .ToListAsync(); sw.Stop(); var codes = teams.Take(5).Select(t => t.Props.Code).ToArray(); return Ok("E110", "Tree Query - WhereHasAncestor", ExampleTier.Free, sw.ElapsedMilliseconds, teams.Count, [ $"Teams with rich ancestors (budget > 500k): {teams.Count}", $"Sample: {string.Join(", ", codes)}" ]); } }