---
title: "Ends-With Query"
description: "Filter RavenDB documents where a field value ends with a specified string using the EndsWith query operator."
url: "https://docs.ravendb.net/7.2/client-api/session/querying/text-search/ends-with-query"
version: "7.2"
language: "csharp"
---

# Ends-With Query

> Client language: C#. Also available for [Python](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/ends-with-query.python.md), [PHP](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/ends-with-query.php.md), [Node.js](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/ends-with-query.nodejs.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - You can query for documents having a field that ends with some specified string.
>
> - Unless explicitly specified, the string comparisons are case-insensitive by default.
>
> - **Note**:  
>   This postfix search causes the server to perform a full index scan.  
>   Instead, consider using a static index that indexes the field in reverse order  
>   and then query with a [prefix search](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/starts-with-query.md), which is much faster.
>
> - In this page:
>   - [EndsWith](#endswith)
>   - [EndsWith (case-sensitive)](#endswith-\(case-sensitive\))
>   - [Negate EndsWith](#negate-endswith)

## EndsWith

### Query

```csharp
List<Product> products = session
  .Query<Product>()
   // Call 'EndsWith' on the field
   // Pass the postfix to search by
  .Where(x => x.Name.EndsWith("Lager"))
  .ToList();

// Results will contain only Product documents having a 'Name' field
// that ends with any case variation of 'lager'
```

### Query\_async

```csharp
List<Product> products = await asyncSession
  .Query<Product>()
   // Call 'EndsWith' on the field
   // Pass the postfix to search by
  .Where(x => x.Name.EndsWith("Lager"))
  .ToListAsync();

// Results will contain only Product documents having a 'Name' field
// that ends with any case variation of 'lager'
```

### DocumentQuery

```csharp
List<Product> products = session.Advanced
  .DocumentQuery<Product>()
   // Call 'WhereEndsWith'
   // Pass the document field and the postfix to search by
  .WhereEndsWith(x => x.Name, "Lager")
  .ToList();

// Results will contain only Product documents having a 'Name' field
// that ends with any case variation of 'lager'
```

### RQL

```sql
from "Products"
where endsWith(Name, "Lager")
```

## EndsWith (case-sensitive)

### Query

```csharp
List<Product> products = session
  .Query<Product>()
   // Pass 'exact: true' to search for an EXACT postfix match
  .Where(x => x.Name.EndsWith("Lager"), exact: true)
  .ToList();

// Results will contain only Product documents having a 'Name' field
// that ends with 'Lager'
```

### Query\_async

```csharp
List<Product> products = await asyncSession
  .Query<Product>()
   // Pass 'exact: true' to search for an EXACT postfix match
  .Where(x => x.Name.EndsWith("Lager"), exact: true)
  .ToListAsync();

// Results will contain only Product documents having a 'Name' field
// that ends with 'Lager'
```

### DocumentQuery

```csharp
List<Product> products = session.Advanced
  .DocumentQuery<Product>()
   // Call 'WhereEndsWith'
   // Pass 'exact: true' to search for an EXACT postfix match
  .WhereEndsWith(x => x.Name, "Lager", exact: true)
  .ToList();

// Results will contain only Product documents having a 'Name' field
// that ends with 'Lager'
```

### RQL

```sql
from "Products"
where exact(endsWith(Name, "Lager"))
```

## Negate EndsWith

### Query

```csharp
List<Product> products = session
  .Query<Product>()
   // Call 'EndsWith' on the field
   // Pass the postfix to search by
  .Where(x => x.Name.EndsWith("Lager") == false)
  .ToList();

// Results will contain only Product documents having a 'Name' field
// that does NOT end with 'lager' or any other case variations of it
```

### Query\_async

```csharp
List<Product> products = await asyncSession
  .Query<Product>()
   // Call 'EndsWith' on the field
   // Pass the postfix to search by
  .Where(x => x.Name.EndsWith("Lager") == false)
  .ToListAsync();

// Results will contain only Product documents having a 'Name' field
// that does NOT end with 'lager' or any other case variations of it
```

### DocumentQuery

```csharp
List<Product> products = session.Advanced
  .DocumentQuery<Product>()
   // Call 'Not' to negate the next predicate
  .Not
   // Call 'WhereEndsWith'
   // Pass the document field and the postfix to search by
  .WhereEndsWith(x => x.Name, "Lager")
  .ToList();

// Results will contain only Product documents having a 'Name' field
// that does NOT end with 'lager' or any other case variations of it
```

### RQL

```sql
from "Products"
where (true and not endsWith(Name, "Lager"))
```

## See also

- [Query overview](https://docs.ravendb.net/7.2/querying/overview.md)
- [Starts-With query](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/starts-with-query.md)
- [Full-text search](https://docs.ravendb.net/7.2/client-api/session/querying/text-search/full-text-search.md)
- [Map indexes](https://docs.ravendb.net/7.2/indexes/map-indexes.md)
