/// <summary> /// Returns the number of elements in a sequence. /// </summary> /// <typeparam name="TSource">The type of the elements of source.</typeparam> /// <param name="source">The sequence that contains the elements to be counted.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The number of elements in the input sequence.</returns> public static Task <Response <int> > CountAsync <TSource>( this IQueryable <TSource> source, CancellationToken cancellationToken = default(CancellationToken)) { CosmosLinqQueryProvider cosmosLinqQueryProvider = source.Provider as CosmosLinqQueryProvider; if (cosmosLinqQueryProvider == null) { return(ResponseHelperAsync(source.Count())); } return(cosmosLinqQueryProvider.ExecuteAggregateAsync <int>( Expression.Call( GetMethodInfoOf <IQueryable <TSource>, int>(Queryable.Count), source.Expression), cancellationToken)); }
/// <summary> /// Computes the sum of a sequence of <see cref="Int32" /> values. /// </summary> /// <param name="source">A sequence of values to calculate the average of.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The average value in the sequence.</returns> public static Task <int> SumAsync( this IQueryable <int> source, CancellationToken cancellationToken = default(CancellationToken)) { CosmosLinqQueryProvider cosmosLinqQueryProvider = source.Provider as CosmosLinqQueryProvider; if (cosmosLinqQueryProvider == null) { return(Task.FromResult(source.Sum())); } return(cosmosLinqQueryProvider.ExecuteAggregateAsync <int>( Expression.Call( GetMethodInfoOf <IQueryable <int>, int>(Queryable.Sum), source.Expression), cancellationToken)); }
/// <summary> /// Computes the sum of a sequence of <see cref="Nullable{Int64}" /> values. /// </summary> /// <param name="source">A sequence of values to calculate the average of.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The average value in the sequence.</returns> public static Task <Response <long?> > SumAsync( this IQueryable <long?> source, CancellationToken cancellationToken = default(CancellationToken)) { CosmosLinqQueryProvider cosmosLinqQueryProvider = source.Provider as CosmosLinqQueryProvider; if (cosmosLinqQueryProvider == null) { return(ResponseHelperAsync(source.Sum())); } return(cosmosLinqQueryProvider.ExecuteAggregateAsync <long?>( Expression.Call( GetMethodInfoOf <IQueryable <long?>, long?>(Queryable.Sum), source.Expression), cancellationToken)); }
/// <summary> /// Computes the average of a sequence of <see cref="Nullable{Int64}" /> values. /// </summary> /// <param name="source">A sequence of values to calculate the average of.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>The average value in the sequence.</returns> public static Task <double?> AverageAsync( this IQueryable <long?> source, CancellationToken cancellationToken = default(CancellationToken)) { CosmosLinqQueryProvider cosmosLinqQueryProvider = source.Provider as CosmosLinqQueryProvider; if (cosmosLinqQueryProvider == null) { return(Task.FromResult(source.Average())); } return(cosmosLinqQueryProvider.ExecuteAggregateAsync <double?>( Expression.Call( GetMethodInfoOf <IQueryable <long?>, double?>(Queryable.Average), source.Expression), cancellationToken)); }