Filter Optimizely Graph results using C# SDK
Filter Optimizely Graph results by string, numeric, boolean, or date values using the C# SDK.
Use .Where() to narrow results by field values. The SDK translates standard C# comparison operators directly into Optimizely Graph filter expressions.
Filter by string equality
var result = await client
.QueryContent<BlogPostPage>()
.Where(x => x.Author == "John Developer")
.GetAsContentAsync();Filter by numeric comparison
var result = await client
.QueryContent<BlogPostPage>()
.Where(x => x.ViewCount > 1000)
.GetAsContentAsync();The supported operators are >, >=, <, <=, and ==.
Filter by boolean value
var result = await client
.QueryContent<BlogPostPage>()
.Where(x => x.IsFeatured == true)
.GetAsContentAsync();Filter by date range
Use && to combine lower and upper bounds in a single .Where() clause:
var result = await client
.QueryContent<BlogPostPage>()
.Where(x => x.StartPublish >= new DateTime(2024, 1, 1) && x.StartPublish <= new DateTime(2024, 12, 31))
.GetAsContentAsync();Combine conditions with AND
All conditions in a single .Where() lambda combine with AND. Every condition must match:
var result = await client
.QueryContent<BlogPostPage>()
.Where(x => x.Author == "John Developer" && x.BlogCategory == "Tutorials" && x.IsFeatured == true)
.GetAsContentAsync();Combine conditions with OR
Use || inside the lambda to combine conditions with OR. Any one condition matching is enough:
var result = await client
.QueryContent<BlogPostPage>()
.Where(x => x.BlogCategory == "Tutorials" || x.BlogCategory == "Advanced")
.GetAsContentAsync();Combine search with filters
Chain .Where() with .SearchFor() to narrow full-text search results. See Search content in Optimizely Graph using C# SDK for details.
Updated 6 days ago
