Skip to content

Conversation

@Scooletz
Copy link
Contributor

@Scooletz Scooletz commented Jan 12, 2026

@Scooletz Scooletz requested a review from Copilot January 12, 2026 12:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR clarifies the proper placement and behavior of the .Statistics method in RavenDB query documentation. The update addresses potential confusion about when and where to call .Statistics to ensure query statistics are properly captured.

Changes:

  • Added important usage guidance for the .Statistics method across multiple documentation versions
  • Clarified that .Statistics must be called on the final query object before execution/materialization
  • Warned about statistics not being carried over when converting between query types

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docs/client-api/session/querying/_how-to-get-query-statistics-csharp.mdx Added Statistics method placement clarification to the current documentation
versioned_docs/version-7.1/client-api/session/querying/_how-to-get-query-statistics-csharp.mdx Applied same clarification to version 7.1 documentation
versioned_docs/version-7.0/client-api/session/querying/_how-to-get-query-statistics-csharp.mdx Applied same clarification to version 7.0 documentation
versioned_docs/version-6.2/client-api/session/querying/_how-to-get-query-statistics-csharp.mdx Applied same clarification to version 6.2 documentation
versioned_docs/version-6.0/client-api/session/querying/_how-to-get-query-statistics-csharp.mdx Applied same clarification to version 6.0 documentation with additional blank line
versioned_docs/version-5.4/client-api/session/querying/_how-to-get-query-statistics-csharp.mdx Applied same clarification to version 5.4 documentation with additional blank line

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Scooletz Scooletz requested a review from reebhub January 12, 2026 12:18
@Scooletz Scooletz self-assigned this Jan 12, 2026
@Scooletz Scooletz added the .NET Pull requests that update .net code label Jan 12, 2026
are returned in the `QueryStatistics` object.

* `Statistics` should be called on the **final query object that is executed/materialized** (e.g. by calling `ToList`, `ToListAsync`, `First`, `FirstOrDefault`, etc.). If you convert between query types (e.g. `ToDocumentQuery()`, `ToAsyncDocumentQuery()`, `ToQueryable()`), a new query object may be created and previously-requested statistics will **not** be carried over. In such cases, the original `stats` variable will remain with its default values.

Copy link
Member

@Danielle9897 Danielle9897 Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Statistics method is NOT available on the IRavenQueryable interface when using a Where predicate.
This means that the sample code below (in the Query and Query_async tabs) must be fixed to:

 List<Employee> employees = session
   .Query<Employee>()
   .Where(x => x.FirstName == "Anne")
   .ToDocumentQuery() // => must convert to DocumentQuery
   .Statistics(out QueryStatistics stats)
   .ToList();

We should also include a basic example of a collection query, one that does not use any filters, where Statistics() can be called directly without conversion.

=> This will be handled separately in issue:
https://issues.hibernatingrhinos.com/issue/RDoc-3645/Get-query-statistics-Fix-examples

As discussed w/ @Scooletz
For now, suggesting the following text for this PR:

* Always call `Statistics()` on the **final** query instance that you will execute - the one on which you ultimately call _ToList()_, _ToListAsync()_, _First()_, _FirstOrDefault()_, and so on.   
  If you call `Statistics()` on one query object and then convert it to a different type (e.g. by calling `ToDocumentQuery()`, `ToQueryable()`), a new query object is created,
  and the previously-requested statistics will not be carried over.  
  In such cases, the original `QueryStatistics` object will remain with its default values. 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes reflected in the commit below.

@ppekrol ppekrol merged commit b8d8e5e into ravendb:main Jan 13, 2026
1 check passed
@Scooletz Scooletz deleted the statistics-placement-clarification branch January 14, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Pull requests that update .net code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants