---
title: "Query vs DocumentQuery"
description: "Compare RavenDB Query and DocumentQuery APIs to choose the right approach for your querying needs, with syntax examples."
url: "https://docs.ravendb.net/7.2/querying/document-query/query-vs-document-query"
version: "7.2"
language: "csharp"
---

# Query vs DocumentQuery

> Client language: C#. Also available for [Java](https://docs.ravendb.net/7.2/querying/document-query/query-vs-document-query.java.md), [Python](https://docs.ravendb.net/7.2/querying/document-query/query-vs-document-query.python.md), [PHP](https://docs.ravendb.net/7.2/querying/document-query/query-vs-document-query.php.md), [Node.js](https://docs.ravendb.net/7.2/querying/document-query/query-vs-document-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**
>
> - Queries in RavenDB can be written using `Query`, `DocumentQuery`, `RawQuery`, or directly with [RQL](https://docs.ravendb.net/7.2/querying/rql/what-is-rql.md).  
>   Learn more in [Query Overview](https://docs.ravendb.net/7.2/querying/overview.md).
>
> - The main differences between `Query` and `DocumentQuery` are outlined in this article.
>
> - In this article:
>   - [API support](#api-support)
>   - [Immutability](#immutability)
>   - [Default query operator](#default-query-operator)

## API support {#api-support}

### `Query`:

- The *Query* API supports LINQ, the essential data access solution in .NET.

- The API exposed by the *Query* method is a wrapper of *DocumentQuery* and is built on top of it.

- When using *Query*, the query is translated into a *DocumentQuery* object,  
  which then builds into an RQL that is sent to the server.

- The available *Query* methods and extensions are listed in [here](https://docs.ravendb.net/7.2/querying/overview.md#custom-methods-and-extensions-for-linq).

### `DocumentQuery`:

- *DocumentQuery* does Not support LINQ.

- It exposes a lower-level API that provides more flexibility and control when building a query.

- When using *DocumentQuery*, the query is translated into an RQL that is sent to the server.

- The available *DocumentQuery* methods and extensions are listed [here](https://docs.ravendb.net/7.2/querying/document-query/what-is-document-query.md#custom-methods-and-extensions).

> **Note**
>
> **Note**:
>
> `Query` and `DocumentQuery` can be converted to one another.  
> This enables you to take advantage of all available API methods & extensions.  
> See [Convert between DocumentQuery and Query](https://docs.ravendb.net/7.2/querying/document-query/what-is-document-query.md#convert-between-documentquery-and-query).

## Immutability {#immutability}

- `Query` is **immutable** while `DocumentQuery` is **mutable**.  
  You might get different results if you try to *reuse* a query.

- The usage of the `Query` method in the following example:

  ```csharp
  IRavenQueryable<User> query = session
      .Query<User>()
      .Where(x => x.Name.StartsWith("A"));

  IRavenQueryable<User> ageQuery = query
      .Where(x => x.Age > 21);

  IRavenQueryable<User> eyeQuery = query
      .Where(x => x.EyeColor == "blue");
  ```

  will result with the following Lucene-syntax queries:

  `query: from Users where startsWith(Name, 'A')`

  `ageQuery: from Users where startsWith(Name, 'A') and Age > 21`

  `eyeQuery: from Users where startsWith(Name, 'A') and EyeColor = 'blue'`

- A similar usage with `DocumentQuery`:

  ```csharp
  IDocumentQuery<User> documentQuery = session
      .Advanced
      .DocumentQuery<User>()
      .WhereStartsWith(x => x.Name, "A");

  IDocumentQuery<User> ageDocumentQuery = documentQuery
      .WhereGreaterThan(x => x.Age, 21);

  IDocumentQuery<User> eyeDocumentQuery = documentQuery
      .WhereEquals(x => x.EyeColor, "blue");

  // Here all of the DocumentQuery variables have the same reference
  ```

  will result with the following Lucene queries:

  `documentQuery: from Users where startsWith(Name, 'A')`  
  (before creating `ageDocumentQuery`)

  `ageDocumentQuery: from Users where startsWith(Name, 'A') and Age > 21`  
  (before creating `eyeDocumentQuery`)

  `eyeDocumentQuery: from Users where startsWith(Name, 'A') and Age > 21 and EyeColor = 'blue'`

  In this case, all created Lucene queries are the same query (actually the same instance).  
  This is an important hint to be aware of if you are going to reuse `DocumentQuery`.

## Default query operator {#default-query-operator}

- Starting from version 4.0, both `Query` and `DocumentQuery` use `AND` as the default operator.  
  (Previously, `Query` used `AND` and `DocumentQuery` used `OR`).

- This behavior can be modified by calling `UsingDefaultOperator`:

```csharp
session
    .Advanced
    .DocumentQuery<User>()
    .UsingDefaultOperator(QueryOperator.Or);
```

## See also

- [Query Overview](https://docs.ravendb.net/7.2/querying/overview.md)
- [What is a Document Query](https://docs.ravendb.net/7.2/querying/document-query/what-is-document-query.md)
- [Filter with Lucene Syntax](https://docs.ravendb.net/7.2/querying/filtering-query-results/filter-with-lucene-syntax.md)
- [Querying an Index](https://docs.ravendb.net/7.2/indexes/querying/query-index.md)
