Path: redb/redb.Examples/Examples/E141_WhereInRedb.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/E141_WhereInRedb.cs
----
using System.Diagnostics;
using redb.Core;
using redb.Examples.Models;
using redb.Examples.Output;
namespace redb.Examples.Examples;
///
/// Filter by list of base field values.
/// WHERE o._id IN (...) without JOIN - very fast.
///
[ExampleMeta("E141", "WhereInRedb - Base Field", "Analytics",
ExampleTier.Free, 141, "WhereIn", "WhereInRedb", "Base", "Filter", RelatedApis = ["IRedbQueryable.WhereInRedb"])]
public class E141_WhereInRedb : ExampleBase
{
public override async Task RunAsync(IRedbService redb)
{
var sw = Stopwatch.StartNew();
// First get some IDs to filter by
var sampleIds = await redb.Query()
.Take(5)
.Select(x => x.id)
.ToListAsync();
if (sampleIds.Count == 0)
{
sw.Stop();
return Fail("E141", "WhereInRedb - Base Field", ExampleTier.Free, sw.ElapsedMilliseconds,
"No employees found. Run E000 first.");
}
var query = redb.Query()
.WhereInRedb(x => x.Id, sampleIds);
// Uncomment to see generated SQL:
// var sql = await query.ToSqlStringAsync();
// Console.WriteLine(sql);
var results = await query.ToListAsync();
sw.Stop();
return Ok("E141", "WhereInRedb - Base Field", ExampleTier.Free, sw.ElapsedMilliseconds, results.Count,
[$"WHERE o._id IN ({string.Join(",", sampleIds.Take(3))}...)", $"Found: {results.Count} (NO JOIN!)"]);
}
}