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

Paginate Optimizely Graph results using C# SDK

Retrieve specific pages of Optimizely Graph results, combine with filters and sorting, and include total counts for navigation.

Use .Skip() and .Limit() to retrieve a specific page of results. Add .IncludeTotal() to get the total count needed to render page navigation.

Basic skip/limit

.Skip() sets how many items to skip, .Limit() sets how many to return:

var result = await client
    .QueryContent<BlogPostPage>()
    .Skip(2)
    .Limit(3)
    .GetAsContentAsync();

This skips the first 2 items and returns the next 3.

Calculate page offsets

For page-number-based navigation, calculate the skip value from the current page and page size:

int pageSize = 10;
int currentPage = 1; // 1-based

var result = await client
    .QueryContent<BlogPostPage>()
    .Skip((currentPage - 1) * pageSize)
    .Limit(pageSize)
    .IncludeTotal()
    .GetAsContentAsync();

int totalPages = (int)Math.Ceiling((double)result.Total!.Value / pageSize);

result.Total is null unless you call .IncludeTotal(). See Include total for more detail.

Pagination with filtering and ordering

All query methods compose freely:

var result = await client
    .QueryContent<BlogPostPage>()
    .Where(x => x.BlogCategory == "Tutorials")
    .OrderBy(x => x.StartPublish, OrderDirection.Descending)
    .Skip((currentPage - 1) * pageSize)
    .Limit(pageSize)
    .IncludeTotal()
    .GetAsContentAsync();