Path: redb/redb.Examples/Examples/E147_WindowPartitionByRedb.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/E147_WindowPartitionByRedb.cs
----
using System.Diagnostics;
using redb.Core;
using redb.Core.Query.Aggregation;
using redb.Examples.Models;
using redb.Examples.Output;
namespace redb.Examples.Examples;
///
/// PartitionByRedb in Window Functions - partition by base IRedbObject field.
/// SQL: PARTITION BY o._id_scheme (NO JOIN for partition key!)
///
[ExampleMeta("E147", "Window - PartitionByRedb", "Analytics",
ExampleTier.Free, 147, "PartitionByRedb", "Window", "NoJoin", RelatedApis = ["IWindowBuilder.PartitionByRedb", "Win.RowNumber"])]
public class E147_WindowPartitionByRedb : ExampleBase
{
public override async Task RunAsync(IRedbService redb)
{
var sw = Stopwatch.StartNew();
// Window with PartitionByRedb (base field) + OrderByDesc (Props field)
var ranked = await redb.Query()
.Take(50)
.WithWindow(w => w
.PartitionByRedb(x => x.SchemeId) // Base field - NO JOIN!
.OrderByDesc(x => x.Salary)) // Props field
.SelectAsync(x => new
{
x.Name,
SchemeId = x.SchemeId,
Salary = x.Props.Salary,
RankInScheme = Win.RowNumber()
});
sw.Stop();
var first = ranked.FirstOrDefault();
return Ok("E147", "Window - PartitionByRedb", ExampleTier.Free, sw.ElapsedMilliseconds, ranked.Count,
[$"PARTITION BY o._id_scheme (NO JOIN!)",
$"Ranked: {ranked.Count} employees",
first != null ? $"Top: #{first.RankInScheme} {first.Name} ${first.Salary:N0}" : "No data"]);
}
}