Path: redb/redb.Examples/Examples/E163_SqlFunctionNested.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/E163_SqlFunctionNested.cs ---- using System.Diagnostics; using redb.Core; using redb.Core.Query; using redb.Examples.Models; using redb.Examples.Output; namespace redb.Examples.Examples; /// /// Demonstrates nested Sql.Function calls for complex SQL expressions. /// Uses SQRT(Salary) > 250 to find employees with Salary > 62,500. /// Pro feature: nested arbitrary SQL function calls. /// [ExampleMeta("E163", "Sql.Function - Nested", "Query", ExampleTier.Pro, 163, "Sql.Function", "SQRT", "Nested", RelatedApis = ["Sql.Function"])] public class E163_SqlFunctionNested : ExampleBase { public override async Task RunAsync(IRedbService redb) { var sw = Stopwatch.StartNew(); // SQRT(Salary) > 250 means Salary > 62,500 var query = redb.Query() .Where(e => Sql.Function("SQRT", e.Salary) > 250) .Take(100); // Uncomment to see generated SQL (contains SQRT): // var sql = await query.ToSqlStringAsync(); // Console.WriteLine(sql); var results = await query.ToListAsync(); var totalCount = await redb.Query() .Where(e => Sql.Function("SQRT", e.Salary) > 250) .CountAsync(); sw.Stop(); var salaries = results.Take(5).Select(e => $"${e.Props.Salary:N0} (√={Math.Sqrt((double)e.Props.Salary):F0})"); return Ok("E163", "Sql.Function - Nested", ExampleTier.Pro, sw.ElapsedMilliseconds, totalCount, [$"SQL: SQRT(Salary) > 250 (Salary > 62,500)", $"Found: {totalCount} employees", $"Salaries: {string.Join(", ", salaries)}"]); } }