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

Overview of Graph C# SDK

The Optimizely Graph C# (.NET) SDK enables strongly typed, LINQ-style querying of content from Optimizely Graph in .NET applications.

The Graph C# SDK provides a strongly typed, LINQ-style API for querying content from Optimizely Graph in .NET applications. Instead of writing raw GraphQL queries, chain C# methods to filter, search, sort, paginate, and shape results.

For foundational concepts and platform capabilities, see the Optimizely Graph documentation. That resource covers indexing, schema design, and search architecture. To migrate from Search & Navigation to Optimizely Graph, review the migration guides for feature mapping and best practices.

Example query

This example demonstrates how a single query chains filtering, searching, sorting, and pagination. It searches BlogPostPage content for optimizely, filters by the Tutorials category, and sorts by publish date descending. The query returns the first 10 results and includes the total match count.

var result = await _graphClient
    .QueryContent<BlogPostPage>()
    .SearchFor("optimizely")
    .UsingFullText()
    .Where(x => x.BlogCategory == "Tutorials")
    .OrderBy(x => x.StartPublish, OrderDirection.Descending)
    .Skip(0)
    .Limit(10)
    .IncludeTotal()
    .GetAsContentAsync();

NuGet packages

Install the following NuGet packages to enable the C# SDK.

PackagePurpose
Optimizely.Graph.Cms.QueryProvides the core Graph C# query API to retrieve content from Optimizely Graph.
Optimizely.Graph.AspNetCoreAdds ASP.NET Core integrations for search tracking and click-through analytics.

Guides for the C# SDK

The following guides explain how to use the C# SDK:

GuideWhat it covers
Quick startInstall, configure, and run your first query
AuthenticationSingle Key versus Basic authentication and security best practices
Search trackingTrack which results users click, Beacon API integration

Query patterns

Each pattern guide demonstrates a specific query operation with code examples and usage scenarios.

Pattern guideWhat it covers
FilteringFilter by string, numeric, boolean, and date values, and combine them with AND or OR logic.
OrderingApply OrderBy and ThenBy for ascending or descending sorts.
SearchingRun full-text search, field-specific search, and relevance boosting.
PaginationImplement Skip and Limit for large result sets.
Include totalReturn the total result count for page navigation.
AggregationsUse facets and counts for category filtering.
Decay functionsApply recency-based relevance scoring.
SynonymsApply synonym expansion through slot-based filters.
Pinned resultsPromote specific items to the top of search results.

Reference

For HTTP error codes, causes, and fixes, see the Error reference.