You are currently browsing legacy 4.1 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Session: Querying: How to Get Query Statistics

Query statistics can provide important information about a query like duration, total number of results, staleness information, etc. To access statistics use the Statistics method.

Syntax

IRavenQueryable<TResult> Statistics(out QueryStatistics stats);

Parameters
stats QueryStatistics Statistics for query.

Example

List<Employee> employees = session.Query<Employee>()
    .Where(x => x.FirstName == "Robert")
    .Statistics(out QueryStatistics stats)
    .ToList();

int totalResults = stats.TotalResults;
long durationInMilliseconds = stats.DurationInMs;