/// <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 of and to add in the batch of future /// queries. /// </param> /// <returns> /// The QueryFutureValue<TResult,TResult> added to the batch of futures queries. /// </returns> public static QueryFutureValue <TResult> FutureValue <TResult>(this IQueryable <TResult> query) { #if EF5 || EF6 var objectQuery = query.GetObjectQuery(); var futureBatch = QueryFutureManager.AddOrGetBatch(objectQuery.Context); var futureQuery = new QueryFutureValue <TResult>(futureBatch, objectQuery); #elif EFCORE QueryFutureBatch futureBatch; QueryFutureValue <TResult> futureQuery; if (query.IsInMemoryQueryContext()) { var context = query.GetInMemoryContext(); futureBatch = QueryFutureManager.AddOrGetBatch(context); futureBatch.IsInMemory = true; futureQuery = new QueryFutureValue <TResult>(futureBatch, query); } else { var context = query.GetDbContext(); futureBatch = QueryFutureManager.AddOrGetBatch(context); futureQuery = new QueryFutureValue <TResult>(futureBatch, query); } #endif futureBatch.Queries.Add(futureQuery); return(futureQuery); }
/// <summary>A DelayedQuery<TResult> extension method that future value.</summary> /// <typeparam name="TResult">Type of the result.</typeparam> /// <param name="query">The query to act on.</param> /// <returns>A FutureQueryValue<TResult,TResult></returns> public static QueryFutureValue <TResult> FutureValue <TResult>(this IQueryable <TResult> query) { var objectQuery = query.GetObjectQuery(); var futureBatch = QueryFutureManager.AddOrGetBatch(objectQuery.Context); var futureQuery = new QueryFutureValue <TResult>(futureBatch, objectQuery); futureBatch.Queries.Add(futureQuery); return(futureQuery); }
/// <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 of and to add in the batch of future /// queries. /// </param> /// <returns> /// The QueryFutureValue<TResult,TResult> added to the batch of futures queries. /// </returns> public static QueryFutureValue <TResult> FutureValue <TResult>(this IQueryable <TResult> query) { #if EF5 || EF6 var objectQuery = query.GetObjectQuery(); var futureBatch = QueryFutureManager.AddOrGetBatch(objectQuery.Context); var futureQuery = new QueryFutureValue <TResult>(futureBatch, objectQuery); #elif EF7 var context = query.GetDbContext(); var futureBatch = QueryFutureManager.AddOrGetBatch(context); var futureQuery = new QueryFutureValue <TResult>(futureBatch, query); #endif futureBatch.Queries.Add(futureQuery); return(futureQuery); }