Class DocumentQueryable
This class provides extension methods for converting a IQueryable<T> object to a IDocumentQuery<T> object.
public static class DocumentQueryable
- Inheritance
-
DocumentQueryable
- Inherited Members
Remarks
The DocumentClient class provides implementation of standard query methods for querying resources in Azure Cosmos DB. These methods enable you to express traversal, filter, and projection operations over data persisted in the Azure Cosmos DB service. They are defined as methods that extend IQueryable, and do not perform any querying directly. Instead, their functionality is to create queries based the resource and query expression provided. The actual query execution occurs when enumeration forces the expression tree associated with an IQueryable object to be executed.
Methods
AsDocumentQuery<T>(IQueryable<T>)
Converts an IQueryable to IDocumentQuery which supports pagination and asynchronous execution in the Azure Cosmos DB service.
public static IDocumentQuery<T> AsDocumentQuery<T>(this IQueryable<T> query)
Parameters
query
IQueryable<T>the IQueryable{T} to be converted.
Returns
- IDocumentQuery<T>
An IDocumentQuery{T} that can evaluate the query.
Type Parameters
T
the type of object to query.
Examples
This example shows how to run a query asynchronously using the AsDocumentQuery() interface.
using (var queryable = client.CreateDocumentQuery<Book>(
collectionLink,
new FeedOptions { MaxItemCount = 10 })
.Where(b => b.Title == "War and Peace")
.AsDocumentQuery())
{
while (queryable.HasMoreResults)
{
foreach(Book b in await queryable.ExecuteNextAsync<Book>())
{
// Iterate through books
}
}
}
AverageAsync(IQueryable<decimal>, CancellationToken)
Computes the average of a sequence of decimal values.
public static Task<decimal> AverageAsync(this IQueryable<decimal> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<decimal>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
AverageAsync(IQueryable<double>, CancellationToken)
Computes the average of a sequence of double values.
public static Task<double> AverageAsync(this IQueryable<double> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<double>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
AverageAsync(IQueryable<int>, CancellationToken)
Computes the average of a sequence of int values.
public static Task<double> AverageAsync(this IQueryable<int> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<int>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
AverageAsync(IQueryable<long>, CancellationToken)
Computes the average of a sequence of long values.
public static Task<double> AverageAsync(this IQueryable<long> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<long>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
AverageAsync(IQueryable<decimal?>, CancellationToken)
Computes the average of a sequence of Nullable<T> values.
public static Task<decimal?> AverageAsync(this IQueryable<decimal?> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<decimal?>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
AverageAsync(IQueryable<double?>, CancellationToken)
Computes the average of a sequence of Nullable<T> values.
public static Task<double?> AverageAsync(this IQueryable<double?> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<double?>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
AverageAsync(IQueryable<int?>, CancellationToken)
Computes the average of a sequence of Nullable<T> values.
public static Task<double?> AverageAsync(this IQueryable<int?> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<int?>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
AverageAsync(IQueryable<long?>, CancellationToken)
Computes the average of a sequence of Nullable<T> values.
public static Task<double?> AverageAsync(this IQueryable<long?> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<long?>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
AverageAsync(IQueryable<float?>, CancellationToken)
Computes the average of a sequence of Nullable<T> values.
public static Task<float?> AverageAsync(this IQueryable<float?> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<float?>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
AverageAsync(IQueryable<float>, CancellationToken)
Computes the average of a sequence of float values.
public static Task<float> AverageAsync(this IQueryable<float> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<float>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
CountAsync<TSource>(IQueryable<TSource>, CancellationToken)
Returns the number of elements in a sequence.
public static Task<int> CountAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<TSource>The sequence that contains the elements to be counted.
cancellationToken
CancellationTokenThe cancellation token.
Returns
Type Parameters
TSource
The type of the elements of source.
MaxAsync<TSource>(IQueryable<TSource>, CancellationToken)
Returns the maximum value in a generic IQueryable<T>.
public static Task<TSource> MaxAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<TSource>A sequence of values to determine the maximum of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TSource>
The maximum value in the sequence.
Type Parameters
TSource
The type of the elements of source.
MinAsync<TSource>(IQueryable<TSource>, CancellationToken)
Returns the minimum value in a generic IQueryable<T>.
public static Task<TSource> MinAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<TSource>A sequence of values to determine the minimum of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TSource>
The minimum value in the sequence.
Type Parameters
TSource
The type of the elements of source.
SumAsync(IQueryable<decimal>, CancellationToken)
Computes the sum of a sequence of decimal values.
public static Task<decimal> SumAsync(this IQueryable<decimal> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<decimal>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
SumAsync(IQueryable<double>, CancellationToken)
Computes the sum of a sequence of double values.
public static Task<double> SumAsync(this IQueryable<double> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<double>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
SumAsync(IQueryable<int>, CancellationToken)
Computes the sum of a sequence of int values.
public static Task<int> SumAsync(this IQueryable<int> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<int>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
SumAsync(IQueryable<long>, CancellationToken)
Computes the sum of a sequence of long values.
public static Task<long> SumAsync(this IQueryable<long> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<long>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
SumAsync(IQueryable<decimal?>, CancellationToken)
Computes the sum of a sequence of Nullable<T> values.
public static Task<decimal?> SumAsync(this IQueryable<decimal?> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<decimal?>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
SumAsync(IQueryable<double?>, CancellationToken)
Computes the sum of a sequence of Nullable<T> values.
public static Task<double?> SumAsync(this IQueryable<double?> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<double?>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
SumAsync(IQueryable<int?>, CancellationToken)
Computes the sum of a sequence of Nullable<T> values.
public static Task<int?> SumAsync(this IQueryable<int?> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<int?>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
SumAsync(IQueryable<long?>, CancellationToken)
Computes the sum of a sequence of Nullable<T> values.
public static Task<long?> SumAsync(this IQueryable<long?> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<long?>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
SumAsync(IQueryable<float?>, CancellationToken)
Computes the sum of a sequence of Nullable<T> values.
public static Task<float?> SumAsync(this IQueryable<float?> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<float?>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
SumAsync(IQueryable<float>, CancellationToken)
Computes the sum of a sequence of float values.
public static Task<float> SumAsync(this IQueryable<float> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<float>A sequence of values to calculate the average of.
cancellationToken
CancellationTokenThe cancellation token.