---
title: "Starts-With Query"
url: "https://docs.ravendb.net/6.2/client-api/session/querying/text-search/starts-with-query"
version: "6.2"
language: "csharp"
---

# Starts-With Query

> Client language: C#. Also available for [Python](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/starts-with-query.python.md), [PHP](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/starts-with-query.php.md), [Node.js](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/starts-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 starts with some specified string.
>
> - Unless explicitly specified, the string comparisons are case-insensitive by default.
>
> - In this page:
>   - [StartsWith](#startswith)
>   - [StartsWith (case-sensitive)](#startswith-\(case-sensitive\))
>   - [Negate StartsWith](#negate-startswith)

## StartsWith

### Query

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

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

### Query\_async

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

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

### DocumentQuery

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

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

### RQL

```sql
from "Products"
where startsWith(Name, "Ch")
```

## StartsWith (case-sensitive)

### Query

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

// Results will contain only Product documents having a 'Name' field
// that starts with 'Ch'
```

### Query\_async

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

// Results will contain only Product documents having a 'Name' field
// that starts with 'Ch'
```

### DocumentQuery

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

// Results will contain only Product documents having a 'Name' field
// that starts with 'Ch'
```

### RQL

```sql
from "Products"
where exact(startsWith(Name, "Ch"))
```

## Negate StartsWith

### Query

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

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

### Query\_async

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

// Results will contain only Product documents having a 'Name' field
// that does NOT start with 'ch' 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 'WhereStartsWith'
   // Pass the document field and the prefix to search by
  .WhereStartsWith(x => x.Name, "Ch")
  .ToList();

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

### RQL

```sql
from "Products"
where (true and not startsWith(Name, "Ch"))
```

## See also

- [Query overview](https://docs.ravendb.net/6.2/client-api/session/querying/how-to-query.md)
- [Ends-With query](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/ends-with-query.md)
- [Full-text search](https://docs.ravendb.net/6.2/client-api/session/querying/text-search/full-text-search.md)
