コード例 #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="T">The type of elements of the query.</typeparam>
        /// <param name="query">
        ///     The query to defer the execution of and to add in the batch of future
        ///     queries.
        /// </param>
        /// <returns>
        ///     The QueryFutureEnumerable&lt;TEntity&gt; added to the batch of futures queries.
        /// </returns>
        public static QueryFutureEnumerable <T> Future <T>(this IQueryable <T> query)
        {
#if EF5 || EF6
            var objectQuery = query.GetObjectQuery();
            var futureBatch = QueryFutureManager.AddOrGetBatch(objectQuery.Context);
            var futureQuery = new QueryFutureEnumerable <T>(futureBatch, objectQuery);
#elif EFCORE
            QueryFutureBatch          futureBatch;
            QueryFutureEnumerable <T> futureQuery;
            if (query.IsInMemoryQueryContext())
            {
                var context = query.GetInMemoryContext();
                futureBatch            = QueryFutureManager.AddOrGetBatch(context);
                futureBatch.IsInMemory = true;
                futureQuery            = new QueryFutureEnumerable <T>(futureBatch, query);
            }
            else
            {
                var context = query.GetDbContext();
                futureBatch = QueryFutureManager.AddOrGetBatch(context);
                futureQuery = new QueryFutureEnumerable <T>(futureBatch, query);
            }
#endif
            futureBatch.Queries.Add(futureQuery);

            return(futureQuery);
        }
コード例 #2
0
        /// <summary>
        ///     An IQueryable&lt;TEntity&gt; extension method that futures the given query.
        /// </summary>
        /// <typeparam name="TEntity">Type of the entity.</typeparam>
        /// <param name="query">The query to act on.</param>
        /// <returns>A QueryFutureEnumerable&lt;TEntity&gt;</returns>
        public static QueryFutureEnumerable <TEntity> Future <TEntity>(this IQueryable <TEntity> query)
        {
            var objectQuery = query.GetObjectQuery();
            var futureBatch = QueryFutureManager.AddOrGetBatch(objectQuery.Context);
            var futureQuery = new QueryFutureEnumerable <TEntity>(futureBatch, objectQuery);

            futureBatch.Queries.Add(futureQuery);

            return(futureQuery);
        }
コード例 #3
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="T">The type of elements of the query.</typeparam>
        /// <param name="query">
        ///     The query to defer the execution of and to add in the batch of future
        ///     queries.
        /// </param>
        /// <returns>
        ///     The QueryFutureEnumerable&lt;TEntity&gt; added to the batch of futures queries.
        /// </returns>
        internal static QueryFutureEnumerable <T> Future <T>(this IQueryable <T> query)
        {
#if EF5 || EF6
            var objectQuery = query.GetObjectQuery();
            var futureBatch = QueryFutureManager.AddOrGetBatch(objectQuery.Context);
            var futureQuery = new QueryFutureEnumerable <T>(futureBatch, objectQuery);
#elif EF7
            var context     = query.GetDbContext();
            var futureBatch = QueryFutureManager.AddOrGetBatch(context);
            var futureQuery = new QueryFutureEnumerable <T>(futureBatch, query);
#endif
            futureBatch.Queries.Add(futureQuery);

            return(futureQuery);
        }