HomeDev GuideRecipesAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Filter Optimizely Graph results

Learn how to use the filter feature in the C# SDK

Use .Where() to narrow results by field values. The SDK translates standard C# comparison operators directly into Optimizely Graph filter expressions.

String equality

var result = await client
    .QueryContent<BlogPostPage>()
    .Where(x => x.Author == "John Developer")
    .GetAsContentAsync();

Numeric comparisons

var result = await client
    .QueryContent<BlogPostPage>()
    .Where(x => x.ViewCount > 1000)
    .GetAsContentAsync();

Supported operators: >, >=, <, <=, ==.

Boolean filtering

var result = await client
    .QueryContent<BlogPostPage>()
    .Where(x => x.IsFeatured == true)
    .GetAsContentAsync();

Date range filtering

Use && to combine lower and upper bounds into a single .Where():

var result = await client
    .QueryContent<BlogPostPage>()
    .Where(x => x.StartPublish >= new DateTime(2024, 1, 1) && x.StartPublish <= new DateTime(2024, 12, 31))
    .GetAsContentAsync();

Multiple conditions (AND)

All conditions in a single .Where() lambda are combined 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();

Multiple conditions (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();

Combining search with filters

You can chain .Where() with .SearchFor() to narrow full-text search results. See Search content in Optimizely Graph using C# SDK for details.