Path: redb/redb.Examples/Examples/E120_ListItemWhereByValue.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/E120_ListItemWhereByValue.cs
----
using System.Diagnostics;
using redb.Core;
using redb.Examples.Models;
using redb.Examples.Output;
namespace redb.Examples.Examples;
///
/// Query filtering by ListItem.Value property.
/// Shows how to filter objects by the Value of a ListItem field.
/// Requires E114-E118 to run first.
///
[ExampleMeta("E120", "ListItem - Where by Value", "List",
ExampleTier.Free, 120, "ListItem", "Where", "Value", "Query", RelatedApis = ["IRedbQueryable.Where", "RedbListItem.Value"])]
public class E120_ListItemWhereByValue : ExampleBase
{
public override async Task RunAsync(IRedbService redb)
{
var sw = Stopwatch.StartNew();
// Query persons where Status.Value == "Active"
var query = redb.Query()
.Where(p => p.Status!.Value == "Active")
.Take(100);
// Uncomment to see generated SQL:
// var sql = await query.ToSqlStringAsync();
// Console.WriteLine(sql);
var results = await query.ToListAsync();
sw.Stop();
if (results.Count == 0)
{
return Ok("E120", "ListItem - Where by Value", ExampleTier.Free, sw.ElapsedMilliseconds, 0,
["No persons with Status='Active' found", "Run E118 first to create test data"]);
}
var firstName = results.FirstOrDefault()?.Props?.Name ?? "N/A";
return Ok("E120", "ListItem - Where by Value", ExampleTier.Free, sw.ElapsedMilliseconds, results.Count,
[$"Filter: Status.Value == 'Active'", $"Found: {results.Count}, First: {firstName}"]);
}
}