{NOTE: }
-
The following options are available to count query results:
{NOTE/}
{PANEL: Count}
-
When the number of resulting items is expected to be an
Int32
variable,
useCount
in a synchronous session (orCountAsync
in an async session). -
Count
is implemented inSystem.Linq
.
CountAsync
is implemented inRaven.Client.Documents
. -
An
OverflowException
will be thrown if the number of items exceedsInt32.MaxValue
.
{NOTE: }
{CODE-TABS} {CODE-TAB:csharp:Query count_1@ClientApi\Session\Querying\CountQueryResultsUsingLinq.cs /} {CODE-TAB:csharp:Query_async count_2@ClientApi\Session\Querying\CountQueryResults.cs /} {CODE-TAB:csharp:DocumentQuery count_3@ClientApi\Session\Querying\CountQueryResults.cs /} {CODE-TAB-BLOCK:sql:RQL} from "Orders" where ShipTo.Country == "UK" limit 0, 0
// The RQL generated will trigger query execution // however, no documents are returned (limit is set 0) {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{PANEL/}
{PANEL: LongCount}
-
When the number of resulting items is expected to be an
Int64
variable,
useLongCount
in a synchronous session (orLongCountAsync
in an async session). -
LongCount
is implemented in bothRaven.Client.Documents
&System.Linq
(use as needed).
LongCountAsync
is implemented inRaven.Client.Documents
.
{NOTE: }
{CODE-TABS} {CODE-TAB:csharp:Query count_4@ClientApi\Session\Querying\CountQueryResults.cs /} {CODE-TAB:csharp:Query_async count_5@ClientApi\Session\Querying\CountQueryResults.cs /} {CODE-TAB:csharp:DocumentQuery count_6@ClientApi\Session\Querying\CountQueryResults.cs /} {CODE-TAB-BLOCK:sql:RQL} from "Orders" where ShipTo.Country == "UK" limit 0, 0
// The RQL generated will trigger query execution // however, no documents are returned (limit is set 0) {CODE-TAB-BLOCK/} {CODE-TABS/}
{NOTE/}
{PANEL/}
{PANEL: Get count from query stats}
-
When executing a query,
you can retrieve the query statistics which include the total number of results. -
The number of results is available in the
QueryStatistics
object as:TotalResults
- an Int32 valueLongTotalResults
- an Int64 value
-
Learn more in Get Query Statistics.
{PANEL/}