Пример #1
0
        /// <summary>
        /// Provides for defering the execution of the <paramref name="source"/> query to a batch of future queries.
        /// </summary>
        /// <typeparam name="T">The type of the elements of <paramref name="source"/>.</typeparam>
        /// <param name="source">An <see cref="T:System.Linq.IQueryable`1"/> to add to the batch of future queries.</param>
        /// <param name="cacheSettings">The cache settings.</param>
        /// <returns>
        /// An instance of <see cref="FutureCount"/> that contains the result of the query.
        /// </returns>
        /// <seealso cref="T:CodeSmith.Data.Linq.FutureCount"/>
        public static FutureCount FutureCacheCount <T>(this IQueryable <T> source, CacheSettings cacheSettings)
        {
            if (source == null)
            {
                return(new FutureCount(0));
            }

            IFutureContext db     = GetFutureContext(source);
            var            future = new FutureCount(source, db.ExecuteFutureQueries, cacheSettings);

            db.FutureQueries.Add(future);
            return(future);
        }
Пример #2
0
        /// <summary>
        /// Provides for defering the execution of the <paramref name="source"/> query to a batch of future queries.
        /// </summary>
        /// <typeparam name="T">The type of the elements of <paramref name="source"/>.</typeparam>
        /// <param name="source">An <see cref="T:System.Linq.IQueryable`1"/> to add to the batch of future queries.</param>
        /// <param name="cacheSettings">The cache settings.</param>
        /// <returns>
        /// An <see cref="T:System.Collections.Generic.IEnumerable`1"/> that contains elements from the input sequence.
        /// </returns>
        /// <seealso cref="T:CodeSmith.Data.Linq.FutureQuery`1"/>
        public static FutureQuery <T> FutureCache <T>(this IQueryable <T> source, CacheSettings cacheSettings)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            IFutureContext db     = GetFutureContext(source);
            var            future = new FutureQuery <T>(source, db.ExecuteFutureQueries, cacheSettings);

            db.FutureQueries.Add(future);
            return(future);
        }
Пример #3
0
        /// <summary>
        /// Provides for defering the execution of the <paramref name="source"/> query to a batch of future queries.
        /// </summary>
        /// <typeparam name="T">The type of the elements of <paramref name="source"/>.</typeparam>
        /// <param name="source">An <see cref="T:System.Linq.IQueryable`1"/> to add to the batch of future queries.</param>
        /// <param name="cacheSettings">The cache settings.</param>
        /// <returns>
        /// An instance of <see cref="T:CodeSmith.Data.Linq.FutureValue`1"/> that contains the result of the query.
        /// </returns>
        /// <seealso cref="T:CodeSmith.Data.Linq.FutureValue`1"/>
        public static FutureValue <T> FutureCacheFirstOrDefault <T>(this IQueryable <T> source, CacheSettings cacheSettings)
        {
            if (source == null)
            {
                return(new FutureValue <T>(default(T)));
            }

            // make sure to only get the first value
            var firstQuery = source.Take(1);

            IFutureContext db     = GetFutureContext(source);
            var            future = new FutureValue <T>(firstQuery, db.ExecuteFutureQueries, cacheSettings);

            db.FutureQueries.Add(future);
            return(future);
        }
Пример #4
0
        private static IFutureContext GetFutureContext(IQueryable source)
        {
            DataContext context = source.GetDataContext();

            if (context == null)
            {
                throw new ArgumentException("The source must originate from a DataContext that implements IFutureContext.", "source");
            }

            IFutureContext futureContext = context as IFutureContext;

            if (futureContext == null)
            {
                throw new ArgumentException("The source must originate from a DataContext that implements IFutureContext.", "source");
            }

            return(futureContext);
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FutureCount" /> class.
 /// </summary>
 /// <param name="query">The query source to use when materializing.</param>
 /// <param name="futureContext">The future context.</param>
 internal FutureCount(IQueryable <int> query, IFutureContext futureContext)
     : base(query, futureContext)
 {
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:EntityFramework.Future.FutureQuery`1" /> class.
 /// </summary>
 /// <param name="query">The query source to use when materializing.</param>
 /// <param name="futureContext">The future context.</param>
 internal FutureQuery(IQueryable <T> query, IFutureContext futureContext)
     : base(query, futureContext)
 {
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FutureQuery&lt;T&gt;" /> class.
 /// </summary>
 /// <param name="query">The query source to use when materializing.</param>
 /// <param name="futureContext">The future context.</param>
 protected FutureQueryBase(IQueryable <T> query, IFutureContext futureContext)
 {
     _query         = query;
     _futureContext = futureContext;
     //_result = null;
 }