Esempio n. 1
0
        public static Task <bool> AnyAsync <TSource>(
            [NotNull] this IQueryable <TSource> source,
            [NotNull] Expression <Func <TSource, bool> > predicate,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(source, "source");
            Check.NotNull(predicate, "predicate");

            cancellationToken.ThrowIfCancellationRequested();

            var provider = source.Provider as IAsyncQueryProvider;

            if (provider != null)
            {
                return(provider.ExecuteAsync <bool>(
                           Expression.Call(
                               null,
                               _anyPredicate.MakeGenericMethod(typeof(TSource)),
                               new[] { source.Expression, Expression.Quote(predicate) }
                               ),
                           cancellationToken));
            }

            throw new InvalidOperationException(Strings.FormatIQueryableProviderNotAsync());
        }
Esempio n. 2
0
        public static Task <int> SumAsync(
            [NotNull] this IQueryable <int> source,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(source, "source");

            var provider = source.Provider as IAsyncQueryProvider;

            if (provider != null)
            {
                return(provider.ExecuteAsync <int>(
                           Expression.Call(
                               null,
                               _sumInt,
                               new[] { source.Expression }
                               ),
                           cancellationToken));
            }

            throw new InvalidOperationException(Strings.FormatIQueryableProviderNotAsync());
        }
Esempio n. 3
0
        public static Task <int> CountAsync <TSource>(
            [NotNull] this IQueryable <TSource> source,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(source, "source");

            cancellationToken.ThrowIfCancellationRequested();

            var provider = source.Provider as IAsyncQueryProvider;

            if (provider != null)
            {
                return(provider.ExecuteAsync <int>(
                           Expression.Call(
                               null,
                               _count.MakeGenericMethod(typeof(TSource)),
                               new[] { source.Expression }),
                           cancellationToken));
            }

            throw new InvalidOperationException(Strings.FormatIQueryableProviderNotAsync());
        }