コード例 #1
0
        public CosmosLinqQuery(
            ContainerCore container,
            CosmosResponseFactory responseFactory,
            CosmosQueryClientCore queryClient,
            string continuationToken,
            QueryRequestOptions cosmosQueryRequestOptions,
            Expression expression,
            bool allowSynchronousQueryExecution,
            CosmosSerializationOptions serializationOptions = null)
        {
            this.container                      = container ?? throw new ArgumentNullException(nameof(container));
            this.responseFactory                = responseFactory ?? throw new ArgumentNullException(nameof(responseFactory));
            this.queryClient                    = queryClient ?? throw new ArgumentNullException(nameof(queryClient));
            this.continuationToken              = continuationToken;
            this.cosmosQueryRequestOptions      = cosmosQueryRequestOptions;
            this.Expression                     = expression ?? Expression.Constant(this);
            this.allowSynchronousQueryExecution = allowSynchronousQueryExecution;
            this.correlatedActivityId           = Guid.NewGuid();
            this.serializationOptions           = serializationOptions;

            this.queryProvider = new CosmosLinqQueryProvider(
                container,
                responseFactory,
                queryClient,
                this.continuationToken,
                cosmosQueryRequestOptions,
                this.allowSynchronousQueryExecution,
                this.queryClient.OnExecuteScalarQueryCallback,
                this.serializationOptions);
        }
コード例 #2
0
        /// <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));
        }
コード例 #3
0
        /// <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));
        }
コード例 #4
0
        /// <summary>
        /// Computes the sum of a sequence of <see cref="Nullable{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)source.Provider).ExecuteAggregateAsync <int?>(
                       Expression.Call(
                           GetMethodInfoOf <IQueryable <int?>, int?>(Queryable.Sum),
                           source.Expression),
                       cancellationToken));
        }
コード例 #5
0
        /// <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));
        }
コード例 #6
0
        /// <summary>
        /// Returns the minimum value in a generic <see cref="IQueryable{TSource}" />.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <param name="source">A sequence of values to determine the minimum of.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The minimum value in the sequence.</returns>
        public static Task <TSource> MinAsync <TSource>(
            this IQueryable <TSource> source,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            CosmosLinqQueryProvider cosmosLinqQueryProvider = source.Provider as CosmosLinqQueryProvider;

            if (cosmosLinqQueryProvider == null)
            {
                return(Task.FromResult(source.Min()));
            }

            return(cosmosLinqQueryProvider.ExecuteAggregateAsync <TSource>(
                       Expression.Call(
                           GetMethodInfoOf <IQueryable <TSource>, TSource>(Queryable.Min),
                           source.Expression),
                       cancellationToken));
        }
コード例 #7
0
 public CosmosLinqQuery(
     CosmosContainerCore container,
     CosmosJsonSerializer cosmosJsonSerializer,
     CosmosQueryClient queryClient,
     QueryRequestOptions cosmosQueryRequestOptions,
     Expression expression,
     bool allowSynchronousQueryExecution)
 {
     this.container                      = container ?? throw new ArgumentNullException(nameof(container));
     this.cosmosJsonSerializer           = cosmosJsonSerializer;
     this.queryClient                    = queryClient;
     this.cosmosQueryRequestOptions      = cosmosQueryRequestOptions;
     this.expression                     = expression ?? Expression.Constant(this);
     this.allowSynchronousQueryExecution = allowSynchronousQueryExecution;
     this.queryProvider                  = new CosmosLinqQueryProvider(
         container,
         cosmosJsonSerializer,
         queryClient,
         cosmosQueryRequestOptions,
         this.allowSynchronousQueryExecution);
     this.correlatedActivityId = Guid.NewGuid();
 }