internal static async Task <HashSet <T> > ToHashSetAsync <T>(this IDbAsyncEnumerable source, CancellationToken cancellationToken) { var hashSet = new HashSet <T>(); await TaskExtensions.WithCurrentCulture(IDbAsyncEnumerableExtensions.ForEachAsync(source, (Action <object>)(e => hashSet.Add((T)e)), cancellationToken)); return(hashSet); }
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)); }
public override IAsyncEnumerable <Object> Execute(Object dataContext, OeQueryContext queryContext) { 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 OeEf6EnumerableToQuerableVisitor().Visit(expression); expression = queryContext.TranslateSource(dataContext, expression); if (queryContext.IsQueryCount()) { countExpression = queryContext.CreateCountExpression(expression); } } IDbAsyncEnumerable asyncEnumerable = (IDbAsyncEnumerable)query.Provider.CreateQuery(expression); IAsyncEnumerable <Object> asyncEnumerator = new OeEf6AsyncEnumerator(asyncEnumerable); if (countExpression != null) { query = queryContext.EntitySetAdapter.GetEntitySet(dataContext); queryContext.TotalCountOfItems = query.Provider.Execute <int>(countExpression); } return(asyncEnumerator); }
internal static Task <TResult> ExecuteSingleAsync <TResult>( IDbAsyncEnumerable <TResult> query, Expression queryRoot, CancellationToken cancellationToken) { return(ObjectQueryProvider.GetAsyncElementFunction <TResult>(queryRoot)(query, cancellationToken)); }
public IDbAsyncEnumerator GetAsyncEnumerator() { IDbAsyncEnumerable asyncEnumerable = inner as IDbAsyncEnumerable; if (asyncEnumerable == null) { throw new InvalidOperationException("The source IQueryable doesn't implement IDbAsyncEnumerable."); } return(asyncEnumerable.GetAsyncEnumerator()); }
private static IDbAsyncEnumerable <T> AsDbAsyncEnumerable <T>(this IQueryable <T> source) { IDbAsyncEnumerable <T> dbAsyncEnumerable = source as IDbAsyncEnumerable <T>; if (dbAsyncEnumerable != null) { return(dbAsyncEnumerable); } throw new InvalidOperationException("IQueryable not async!"); }
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)); } } }
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); } }
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); } }
internal static Task <HashSet <T> > ToHashSetAsync <T>(this IDbAsyncEnumerable source) { return(IDbAsyncEnumerableExtensions.ToHashSetAsync <T>(source, CancellationToken.None)); }
public OeEf6AsyncEnumerator(IDbAsyncEnumerable asyncEnumerable) { _asyncEnumerator = asyncEnumerable.GetAsyncEnumerator(); }