Ejemplo n.º 1
0
        /// <summary>
        ///     Defer the execution of the <paramref name="query" /> and batch the query command with other
        ///     future queries. The batch is executed when a future query requires a database round trip.
        /// </summary>
        /// <typeparam name="TResult">The type of the query result.</typeparam>
        /// <param name="query">The query to defer the execution and to add in the batch of future queries.</param>
        /// <returns>
        ///     The QueryFutureValue&lt;TResult,TResult&gt; added to the batch of futures queries.
        /// </returns>
        public static QueryFutureValue <TResult> FutureValue <TResult>(this QueryDeferred <TResult> query)
        {
            if (!QueryFutureManager.AllowQueryBatch)
            {
                var futureValue = new QueryFutureValue <TResult>(null, null);
                futureValue.GetResultDirectly(query.Query);
                return(futureValue);
            }

#if EF5 || EF6
            var objectQuery = query.Query.GetObjectQuery();
            var futureBatch = QueryFutureManager.AddOrGetBatch(objectQuery.Context);
            var futureQuery = new QueryFutureValue <TResult>(futureBatch, objectQuery);
#elif EFCORE
            QueryFutureBatch           futureBatch;
            QueryFutureValue <TResult> futureQuery;
            if (query.Query.IsInMemoryQueryContext())
            {
                var context = query.Query.GetInMemoryContext();
                futureBatch                       = QueryFutureManager.AddOrGetBatch(context);
                futureBatch.IsInMemory            = true;
                futureQuery                       = new QueryFutureValue <TResult>(futureBatch, query.Query);
                futureQuery.InMemoryDeferredQuery = query;
            }
            else
            {
                var context = query.Query.GetDbContext();
                futureBatch = QueryFutureManager.AddOrGetBatch(context);
                futureQuery = new QueryFutureValue <TResult>(futureBatch, query.Query);
            }
#endif
            futureBatch.Queries.Add(futureQuery);

            return(futureQuery);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Defer the execution of the <paramref name="query" /> and batch the query command with other
        ///     future queries. The batch is executed when a future query requires a database round trip.
        /// </summary>
        /// <typeparam name="TResult">The type of the query result.</typeparam>
        /// <param name="query">The query to defer the execution and to add in the batch of future queries.</param>
        /// <returns>
        ///     The QueryFutureValue&lt;TResult,TResult&gt; added to the batch of futures queries.
        /// </returns>
        public static QueryFutureValue <TResult> FutureValue <TResult>(this QueryDeferred <TResult> query)
        {
#if EF5 || EF6
            var objectQuery = query.Query.GetObjectQuery();
            var futureBatch = QueryFutureManager.AddOrGetBatch(objectQuery.Context);
            var futureQuery = new QueryFutureValue <TResult>(futureBatch, objectQuery);
#elif EF7
            var context     = query.Query.GetDbContext();
            var futureBatch = QueryFutureManager.AddOrGetBatch(context);
            var futureQuery = new QueryFutureValue <TResult>(futureBatch, query.Query);
#endif
            futureBatch.Queries.Add(futureQuery);

            return(futureQuery);
        }