/// <summary>Immediately executes a sequence query and return a list of all the results once it has completed.</summary>
        public static Task <List <T> > ToListAsync <T>(this IFdbAsyncSequenceQueryable <T> query, CancellationToken ct = default(CancellationToken))
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            if (ct.IsCancellationRequested)
            {
                return(TaskHelpers.FromCancellation <List <T> >(ct));
            }

            return(query.Provider.ExecuteAsync <List <T> >(query.Expression, ct));
        }
Exemplo n.º 2
0
        /// <summary>Immediately executes a sequence query and return an array of all the results once it has completed.</summary>
        public static Task <T[]> ToArrayAsync <T>(this IFdbAsyncSequenceQueryable <T> query, CancellationToken ct = default(CancellationToken))
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            if (ct.IsCancellationRequested)
            {
                return(Task.FromCanceled <T[]>(ct));
            }

            return(query.Provider.ExecuteAsync <T[]>(query.Expression, ct));
        }
Exemplo n.º 3
0
        /// <summary>Returns the first element of a sequence query</summary>
        public static Task <int> CountAsync <T>(this IFdbAsyncSequenceQueryable <T> query, CancellationToken ct = default(CancellationToken))
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            var expr = FdbQueryExpressions.Single <T, int>(
                (FdbQuerySequenceExpression <T>)query.Expression,
                "CountAsync",
                (source, _ct) => source.CountAsync(_ct)
                );

            return(query.Provider.CreateQuery <int>(expr).ExecuteSingle(ct));
        }
Exemplo n.º 4
0
        /// <summary>Returns an async sequence that would return the results of this query as they arrive.</summary>
        public static IAsyncEnumerable <T> ToAsyncEnumerable <T>(this IFdbAsyncSequenceQueryable <T> query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            var sequenceQuery = query as FdbAsyncSequenceQuery <T>;

            if (sequenceQuery == null)
            {
                throw new ArgumentException("Source query type not supported", nameof(query));
            }

            return(sequenceQuery.ToEnumerable());
        }
Exemplo n.º 5
0
        /// <summary>Returns the first element of a sequence query</summary>
        public static Task <T> FirstOrDefaultAsync <T>(this IFdbAsyncSequenceQueryable <T> query, CancellationToken ct = default(CancellationToken))
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            if (ct.IsCancellationRequested)
            {
                return(Task.FromCanceled <T>(ct));
            }

            var expr = FdbQueryExpressions.Single <T, T>(
                (FdbQuerySequenceExpression <T>)query.Expression,
                "FirstOrDefaultAsync",
                (source, _ct) => source.FirstOrDefaultAsync(_ct)
                );

            return(query.Provider.CreateQuery <T>(expr).ExecuteSingle(ct));
        }
Exemplo n.º 6
0
        /// <summary>Filters a sequence query of values based on a predicate.</summary>
        public static IFdbAsyncSequenceQueryable <T> Where <T>(this IFdbAsyncSequenceQueryable <T> query, Expression <Func <T, bool> > predicate)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            var sourceExpr = query.Expression as FdbQuerySequenceExpression <T>;

            if (sourceExpr == null)
            {
                throw new ArgumentException("query");
            }

            var expr = FdbQueryExpressions.Filter(sourceExpr, predicate);

            return(query.Provider.CreateSequenceQuery <T>(expr));
        }
Exemplo n.º 7
0
        /// <summary>Projects each element of a sequence query into a new form.</summary>
        public static IFdbAsyncSequenceQueryable <R> Select <T, R>(this IFdbAsyncSequenceQueryable <T> query, Expression <Func <T, R> > selector)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            var sourceExpr = query.Expression as FdbQuerySequenceExpression <T>;

            if (sourceExpr == null)
            {
                throw new ArgumentException("query");
            }

            var expr = FdbQueryExpressions.Transform(sourceExpr, selector);

            return(query.Provider.CreateSequenceQuery <R>(expr));
        }
Exemplo n.º 8
0
 internal static Task <T> ExecuteSequence <T>(this IFdbAsyncSequenceQueryable <T> query, CancellationToken ct = default(CancellationToken))
 {
     return(query.Provider.ExecuteAsync <T>(query.Expression, ct));
 }