Class CosmosLinqExtensions
This class provides extension methods for cosmos LINQ code.
public static class CosmosLinqExtensions
- Inheritance
-
CosmosLinqExtensions
- Inherited Members
Methods
AverageAsync(IQueryable<decimal>, CancellationToken)
Computes the average of a sequence of decimal values.
public static Task<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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.
IsDefined(object)
Determines if a certain property is defined or not. This method is to be used in LINQ expressions only and will be evaluated on server. There's no implementation provided in the client library.
public static bool IsDefined(this object obj)
Parameters
obj
object
Returns
- bool
Returns true if this property is defined otherwise returns false.
Examples
var isDefinedQuery = documents.Where(document => document.Name.IsDefined());
IsNull(object)
Determines if a certain property is null or not. This method is to be used in LINQ expressions only and will be evaluated on server. There's no implementation provided in the client library.
public static bool IsNull(this object obj)
Parameters
obj
object
Returns
- bool
Returns true if this property is null otherwise returns false.
Examples
var isNullQuery = documents.Where(document => document.Name.IsNull());
IsPrimitive(object)
Determines if a certain property is of primitive JSON type. This method is to be used in LINQ expressions only and will be evaluated on server. There's no implementation provided in the client library.
public static bool IsPrimitive(this object obj)
Parameters
obj
object
Returns
- bool
Returns true if this property is null otherwise returns false.
Examples
var isPrimitiveQuery = documents.Where(document => document.Name.IsPrimitive());
Remarks
Primitive JSON types (Double, String, Boolean and Null)
MaxAsync<TSource>(IQueryable<TSource>, CancellationToken)
Returns the maximum value in a generic IQueryable<T>.
public static Task<Response<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
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<Response<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
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<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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<Response<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
ToFeedIterator<T>(IQueryable<T>)
This extension method gets the FeedIterator from LINQ IQueryable to execute query asynchronously. This will create the fresh new FeedIterator when called.
public static FeedIterator<T> ToFeedIterator<T>(this IQueryable<T> query)
Parameters
query
IQueryable<T>the IQueryable{T} to be converted.
Returns
- FeedIterator<T>
An iterator to go through the items.
Type Parameters
T
the type of object to query.
Examples
This example shows how to get FeedIterator from LINQ.
IOrderedQueryable<ToDoActivity> linqQueryable = this.Container.GetItemLinqQueryable<ToDoActivity>();
using (FeedIterator<ToDoActivity> setIterator = linqQueryable.Where(item => (item.taskNum < 100)).ToFeedIterator()
ToQueryDefinition<T>(IQueryable<T>)
This method generate query definition from LINQ query.
public static QueryDefinition ToQueryDefinition<T>(this IQueryable<T> query)
Parameters
query
IQueryable<T>the IQueryable{T} to be converted.
Returns
- QueryDefinition
The queryDefinition which can be used in query execution.
Type Parameters
T
the type of object to query.
Examples
This example shows how to generate query definition from LINQ.
IQueryable<T> queryable = container.GetItemsQueryIterator<T>(allowSynchronousQueryExecution = true)
.Where(t => b.id.contains("test"));
QueryDefinition queryDefinition = queryable.ToQueryDefinition();
ToStreamIterator<T>(IQueryable<T>)
This extension method gets the FeedIterator from LINQ IQueryable to execute query asynchronously. This will create the fresh new FeedIterator when called.
public static FeedIterator ToStreamIterator<T>(this IQueryable<T> query)
Parameters
query
IQueryable<T>the IQueryable{T} to be converted.
Returns
- FeedIterator
An iterator to go through the items.
Type Parameters
T
the type of object to query.
Examples
This example shows how to get FeedIterator from LINQ.
IOrderedQueryable<ToDoActivity> linqQueryable = this.Container.GetItemLinqQueryable<ToDoActivity>();
using (FeedIterator setIterator = linqQueryable.Where(item => (item.taskNum < 100)).ToFeedIterator()