/// <summary> /// This method generate query definition from LINQ query. /// </summary> /// <typeparam name="T">the type of object to query.</typeparam> /// <param name="query">the IQueryable{T} to be converted.</param> /// <returns>The queryDefinition which can be used in query execution.</returns> /// <example> /// This example shows how to generate query definition from LINQ. /// /// <code language="c#"> /// <![CDATA[ /// IQueryable<T> queryable = container.GetItemsQueryIterator<T>(allowSynchronousQueryExecution = true) /// .Where(t => b.id.contains("test")); /// QueryDefinition queryDefinition = queryable.ToQueryDefinition(); /// ]]> /// </code> /// </example> public static QueryDefinition ToQueryDefinition <T>(this IQueryable <T> query) { CosmosLinqQuery <T> linqQuery = query as CosmosLinqQuery <T>; if (linqQuery == null) { throw new ArgumentOutOfRangeException(nameof(linqQuery), "ToSqlQueryText is only supported on cosmos LINQ query operations"); } return(linqQuery.ToQueryDefinition()); }
/// <summary> /// This extension method gets the FeedIterator from LINQ IQueryable to execute query asynchronously. /// This will create the fresh new FeedIterator when called. /// </summary> /// <typeparam name="T">the type of object to query.</typeparam> /// <param name="query">the IQueryable{T} to be converted.</param> /// <returns>An iterator to go through the items.</returns> /// <example> /// This example shows how to get FeedIterator from LINQ. /// /// <code language="c#"> /// <![CDATA[ /// IOrderedQueryable<ToDoActivity> linqQueryable = this.Container.GetItemLinqQueryable<ToDoActivity>(); /// FeedIterator setIterator = linqQueryable.Where(item => (item.taskNum < 100)).ToFeedIterator() /// ]]> /// </code> /// </example> public static FeedIterator ToStreamIterator <T>(this IQueryable <T> query) { CosmosLinqQuery <T> linqQuery = query as CosmosLinqQuery <T>; if (linqQuery == null) { throw new ArgumentOutOfRangeException(nameof(linqQuery), "ToStreamFeedIterator is only supported on cosmos LINQ query operations"); } return(linqQuery.ToStreamIterator()); }
//Sync execution of query via direct invoke on IQueryProvider. public object Execute(Expression expression) { Type cosmosQueryType = typeof(CosmosLinqQuery <bool>).GetGenericTypeDefinition().MakeGenericType(typeof(object)); CosmosLinqQuery <object> documentQuery = (CosmosLinqQuery <object>)Activator.CreateInstance( cosmosQueryType, this.container, this.cosmosJsonSerializer, this.queryClient, this.cosmosQueryRequestOptions, this.allowSynchronousQueryExecution); return(documentQuery.ToList().FirstOrDefault()); }
public TResult Execute <TResult>(Expression expression) { Type cosmosQueryType = typeof(CosmosLinqQuery <bool>).GetGenericTypeDefinition().MakeGenericType(typeof(TResult)); CosmosLinqQuery <TResult> cosmosLINQQuery = (CosmosLinqQuery <TResult>)Activator.CreateInstance( cosmosQueryType, this.container, this.cosmosJsonSerializer, this.queryClient, this.cosmosQueryRequestOptions, expression, this.allowSynchronousQueryExecution); this.onExecuteScalarQueryCallback?.Invoke(cosmosLINQQuery); return(cosmosLINQQuery.ToList().FirstOrDefault()); }
//Sync execution of query via direct invoke on IQueryProvider. public object Execute(Expression expression) { Type cosmosQueryType = typeof(CosmosLinqQuery <bool>).GetGenericTypeDefinition().MakeGenericType(typeof(object)); CosmosLinqQuery <object> cosmosLINQQuery = (CosmosLinqQuery <object>)Activator.CreateInstance( cosmosQueryType, this.container, this.responseFactory, this.queryClient, this.continuationToken, this.cosmosQueryRequestOptions, this.allowSynchronousQueryExecution); this.onExecuteScalarQueryCallback?.Invoke(cosmosLINQQuery); return(cosmosLINQQuery.ToList().FirstOrDefault()); }
public async Task <Response <TResult> > ExecuteAggregateAsync <TResult>( Expression expression, CancellationToken cancellationToken = default(CancellationToken)) { Type cosmosQueryType = typeof(CosmosLinqQuery <bool>).GetGenericTypeDefinition().MakeGenericType(typeof(TResult)); CosmosLinqQuery <TResult> cosmosLINQQuery = (CosmosLinqQuery <TResult>)Activator.CreateInstance( cosmosQueryType, this.container, this.responseFactory, this.queryClient, this.continuationToken, this.cosmosQueryRequestOptions, expression, this.allowSynchronousQueryExecution, this.serializationOptions); return(await cosmosLINQQuery.AggregateResultAsync()); }