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

Filter Optimizely Graph results with the 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 into Optimizely Graph filter expressions.

Filter by string equality

Match content by an exact field value, such as posts by a specific author.

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

Filter by numeric comparison

Compare numeric fields against a threshold to find content above, below, or at a specific value.

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

The supported operators are >, >=, <, <=, and ==.

Filter by boolean value

Select content based on a true or false property, such as retrieving only featured posts.

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 with the C# SDK for details.