---
title: Order Optimizely Graph results with the C# SDK
slug: cms-13/docs/ordering
docTags: 
createdAt: 2026-07-30T20:22:02.890Z
---

Use `.OrderBy()` to sort results by any indexed field. Chain `.ThenBy()` for secondary sorts.

`OrderDirection` is an enum in the `Optimizely.Graph.Cms.Query.Implementation` namespace.

## Sort ascending

Return results from lowest to highest value for the specified field.

```csharp
await client
    .QueryContent<BlogPostPage>()
    .OrderBy(x => x.StartPublish, OrderDirection.Ascending)
    .GetAsContentAsync();
```

## Sort descending

Return results from highest to lowest value for the specified field.

```csharp
await client
    .QueryContent<BlogPostPage>()
    .OrderBy(x => x.StartPublish, OrderDirection.Descending)
    .GetAsContentAsync();
```

## Sort by multiple fields

Use `.ThenBy()` to apply a secondary sort when primary values are equal:

```csharp
await client
    .QueryContent<BlogPostPage>()
    .OrderBy(x => x.BlogCategory, OrderDirection.Ascending)
    .ThenBy(x => x.StartPublish, OrderDirection.Descending)
    .GetAsContentAsync();
```

Results sort alphabetically by category, then by newest publish date within each category.

## Sort by numeric fields

Sort by any indexed numeric property, such as a rating or view count.

```csharp
await client
    .QueryContent<BlogPostPage>()
    .OrderBy(x => x.Rating, OrderDirection.Descending)
    .GetAsContentAsync();
```

## Combine sort with filters and pagination

`.OrderBy()` composes freely with `.Where()`, `.Skip()`, `.Limit()`, and other query methods:

```csharp
await client
    .QueryContent<BlogPostPage>()
    .Where(x => x.BlogCategory == "Tutorials")
    .OrderBy(x => x.StartPublish, OrderDirection.Descending)
    .Limit(10)
    .GetAsContentAsync();
```
