Path: redb/redb.Examples/Examples/E139_DistinctRedb.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/E139_DistinctRedb.cs ---- using System.Diagnostics; using redb.Core; using redb.Examples.Models; using redb.Examples.Output; namespace redb.Examples.Examples; /// /// DISTINCT ON base fields (without Id) for finding duplicates. /// Finds objects with identical Name, CodeInt etc. (potential duplicates). /// [ExampleMeta("E139", "DistinctRedb - Find Duplicates", "Analytics", ExampleTier.Pro, 139, "Distinct", "DistinctRedb", "Duplicates", RelatedApis = ["IRedbQueryable.DistinctRedb"])] public class E139_DistinctRedb : ExampleBase { public override async Task RunAsync(IRedbService redb) { var sw = Stopwatch.StartNew(); var query = redb.Query() .OrderByRedb(o => o.Id) .DistinctRedb() .Take(100); // Uncomment to see generated SQL: // var sql = await query.ToSqlStringAsync(); // Console.WriteLine(sql); var unique = await query.ToListAsync(); sw.Stop(); return Ok("E139", "DistinctRedb - Find Duplicates", ExampleTier.Pro, sw.ElapsedMilliseconds, unique.Count, [$"DISTINCT ON (base fields except _id)", $"Unique: {unique.Count} objects"]); } }