/// <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); }
/// <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); }
/// <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); }
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); }
/// <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) { }
/// <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) { }
/// <summary> /// Initializes a new instance of the <see cref="FutureQuery<T>" /> 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; }