コード例 #1
0
        public override Db.OeAsyncEnumerator ExecuteEnumerator(Object dataContext, OeQueryContext queryContext, CancellationToken cancellationToken)
        {
            Expression           expression;
            MethodCallExpression countExpression = null;
            IQueryable           query           = queryContext.EntitySetAdapter.GetEntitySet(dataContext);

            if (base.QueryCache.AllowCache)
            {
                expression = GetFromCache(queryContext, (T)dataContext, base.QueryCache, out countExpression);
            }
            else
            {
                expression = queryContext.CreateExpression(new OeConstantToVariableVisitor());
                expression = new EnumerableToQuerableVisitor().Visit(expression);
                expression = queryContext.TranslateSource(dataContext, expression);

                if (queryContext.ODataUri.QueryCount.GetValueOrDefault())
                {
                    countExpression = OeQueryContext.CreateCountExpression(expression);
                }
            }

            IDbAsyncEnumerable asyncEnumerable = (IDbAsyncEnumerable)query.Provider.CreateQuery(expression);

            Db.OeAsyncEnumerator asyncEnumerator = new OeEf6AsyncEnumerator(asyncEnumerable.GetAsyncEnumerator(), cancellationToken);
            if (countExpression != null)
            {
                query = queryContext.EntitySetAdapter.GetEntitySet(dataContext);
                asyncEnumerator.Count = query.Provider.Execute <int>(countExpression);
            }

            return(base.OperationAdapter.ApplyBoundFunction(asyncEnumerator, queryContext));
        }
コード例 #2
0
        public IDbAsyncEnumerator GetAsyncEnumerator()
        {
            IDbAsyncEnumerable asyncEnumerable = inner as IDbAsyncEnumerable;

            if (asyncEnumerable == null)
            {
                throw new InvalidOperationException("The source IQueryable doesn't implement IDbAsyncEnumerable.");
            }
            return(asyncEnumerable.GetAsyncEnumerator());
        }
コード例 #3
0
        public static async ValueTask <IReadOnlyCollection <T> > EnumerateAsyncEnumerable <T>(IDbAsyncEnumerable <T> asyncEnumerable, int estimatedResultCount, CancellationToken cancellationToken)
        {
            using (var enumerator = asyncEnumerable.GetAsyncEnumerator())
            {
                List <T> result = new List <T>(capacity: estimatedResultCount);
                while (await enumerator.MoveNextAsync(cancellationToken).ConfigureAwait(false))
                {
                    result.Add(enumerator.Current);
                }

                return(result);
            }
        }
コード例 #4
0
 internal static async Task ForEachAsync(this IDbAsyncEnumerable source, Action <object> action, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     using (IDbAsyncEnumerator asyncEnumerator = source.GetAsyncEnumerator())
     {
         if (await TaskExtensions.WithCurrentCulture <bool>(asyncEnumerator.MoveNextAsync(cancellationToken)))
         {
             Task <bool> moveNextTask;
             do
             {
                 cancellationToken.ThrowIfCancellationRequested();
                 object current = asyncEnumerator.Current;
                 moveNextTask = asyncEnumerator.MoveNextAsync(cancellationToken);
                 action(current);
             }while (await TaskExtensions.WithCurrentCulture <bool>(moveNextTask));
         }
     }
 }
コード例 #5
0
        static async Task <IEnumerable> EnumerateAsync <TEntity>(IDbAsyncEnumerable enumerable, CancellationToken cancellationToken)
        {
            using (var iterator = enumerable.GetAsyncEnumerator())
            {
                if (!await iterator.MoveNextAsync(cancellationToken).ConfigureAwait(false))
                {
                    return(Array.Empty <TEntity>());
                }

                var results = new List <TEntity>()
                {
                    (TEntity)iterator.Current
                };

                while (await iterator.MoveNextAsync(cancellationToken).ConfigureAwait(false))
                {
                    results.Add((TEntity)iterator.Current);
                }

                return(results);
            }
        }
コード例 #6
0
 public OeEf6AsyncEnumerator(IDbAsyncEnumerable asyncEnumerable)
 {
     _asyncEnumerator = asyncEnumerable.GetAsyncEnumerator();
 }