---
title: Include the total count in Optimizely Graph queries with the C# SDK
slug: cms-13/docs/include-total
docTags: 
createdAt: 2026-07-30T20:22:04.235Z
---

Call `.IncludeTotal()` to get the total number of items matching your query. Without it, `result.Total` is `null`.

## Get the total count for a query

Retrieve the total number of matching items alongside query results.

```csharp
var result = await client
    .QueryContent<BlogPostPage>()
    .IncludeTotal()
    .GetAsContentAsync();

int total = result.Total!.Value;
```

## Use the total count for pagination

Use the total count to calculate the number of pages:

```csharp
int pageSize = 10;
int currentPage = 1;

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

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

## Total reflects active filters

The count reflects the filtered result set, not the full collection:

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

// Total is the count of featured posts only, not all blog posts
var featuredTotal = result.Total;
```

## Total is consistent across pages

Fetch the total on page 1 and reuse it for all subsequent page navigation. It does not change between paginated calls for the same query:

```csharp
// Page 1: capture total here
var page1 = await client
    .QueryContent<BlogPostPage>()
    .Skip(0)
    .Limit(10)
    .IncludeTotal()
    .GetAsContentAsync();

int total = page1.Total!.Value; // Use this for all page navigation

// Page 2: total is the same
var page2 = await client
    .QueryContent<BlogPostPage>()
    .Skip(10)
    .Limit(10)
    .IncludeTotal()
    .GetAsContentAsync();
```

For pagination patterns that use this total, see [Paginate Optimizely Graph results with the C# SDK](docId\:W3aOzwcLJHZ_-OYEdo1M6).
