Path: redb/redb.Examples/Examples/E185_WhereBool.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/E185_WhereBool.cs
----
using System.Diagnostics;
using redb.Core;
using redb.Examples.Models;
using redb.Examples.Output;
namespace redb.Examples.Examples;
///
/// Demonstrates filtering by conditions that can be simplified.
/// Shows different ways to filter including combined conditions.
///
[ExampleMeta("E185", "Where - Combined Conditions", "Query",
ExampleTier.Free, 185, "Where", "Combined", "Multiple", RelatedApis = ["IRedbQueryable.Where"])]
public class E185_WhereBool : ExampleBase
{
public override async Task RunAsync(IRedbService redb)
{
var sw = Stopwatch.StartNew();
// Combined conditions: Age > 30 AND Salary > 70000
var expHighEarnersCount = await redb.Query()
.Where(e => e.Age > 30 && e.Salary > 70000m)
.CountAsync();
var expHighEarners = await redb.Query()
.Where(e => e.Age > 30 && e.Salary > 70000m)
.Take(5)
.ToListAsync();
// OR conditions: Department == "IT" OR Department == "Engineering"
var techDeptCount = await redb.Query()
.Where(e => e.Department == "IT" || e.Department == "Engineering")
.CountAsync();
sw.Stop();
var names = expHighEarners.Take(3).Select(e => $"{e.Props.FirstName} ({e.Props.Age}, ${e.Props.Salary:N0})");
return Ok("E185", "Where - Combined Conditions", ExampleTier.Free, sw.ElapsedMilliseconds,
expHighEarnersCount + techDeptCount,
[$"Age > 30 AND Salary > 70000: {expHighEarnersCount}",
$"IT OR Engineering: {techDeptCount}",
$"Samples: {string.Join(", ", names)}"]);
}
}