public static Task <TSource[]> ToArrayEFCoreAsync <TSource>( this IQueryable <TSource> source, CancellationToken cancellationToken = default(CancellationToken)) { return(EntityFrameworkQueryableExtensions.ToArrayAsync( source, cancellationToken)); }
public static Task <T[]> ToArrayAsync <T>(this IQueryable <T> source) where T : class { if (source is EntitySet <T> ) { source = (source as EntitySet <T>).DbSet; } return(EntityFrameworkQueryableExtensions.ToArrayAsync(source)); }
/// <summary> /// ToArrayAsync /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="queryable"></param> /// <returns></returns> public static async Task <TEntity[]> ToArrayAsync <TEntity>(this IQueryable <TEntity> queryable) where TEntity : class { if (queryable is IMongoQueryable <TEntity> ) { return((await queryable.ToListAsync() .ConfigureAwait(false)).ToArray()); } return(await EntityFrameworkQueryableExtensions.ToArrayAsync(queryable) .ConfigureAwait(false)); }
public override async Task <IEnumerable <T> > DoQueryAsync <T>(string command, object[] parameters, CancellationToken token = default) { var set = _dbContext.Value.Set <T>(); if (set == null) { throw new EfCoreDirectSqlException($"Cannot locate set of type '{typeof(T)}' in DbContext"); } var r = await EntityFrameworkQueryableExtensions.ToArrayAsync(set.FromSqlRaw(command, parameters), token); return(r.AsEnumerable()); }
public virtual async Task <IPagedModel <TEntity> > PagedAsync(int pageIndex, int pageSize, Expression <Func <TEntity, bool> > whereExpression, Expression <Func <TEntity, object> > orderByExpression, bool ascending = false, bool writeDb = false, CancellationToken cancellationToken = default) { var dbSet = this.GetDbSet(writeDb, false); var total = await EntityFrameworkQueryableExtensions.CountAsync(dbSet, whereExpression, cancellationToken); if (total == 0) { return new PagedModel <TEntity>() { PageSize = pageSize } } ; if (pageIndex <= 0) { pageIndex = 1; } if (pageSize <= 0) { pageSize = 10; } var query = dbSet.Where(whereExpression); query = ascending ? query.OrderBy(orderByExpression) : query.OrderByDescending(orderByExpression); var data = await EntityFrameworkQueryableExtensions.ToArrayAsync( query.Skip((pageIndex - 1) * pageSize).Take(pageSize) , cancellationToken); return(new PagedModel <TEntity>() { PageIndex = pageIndex, PageSize = pageSize, TotalCount = total, Data = data }); } }
public async Task TestAsyncMethods([Values(true, false)] bool enableFilter) { using (var ctx = CreateContext(enableFilter)) { var query = ctx.Products.AsQueryable().Where(p => p.ProductName.Contains("a")); var expectedArray = await query.ToArrayAsync(); var expectedDictionary = await query.ToDictionaryAsync(p => p.ProductId); var expectedAny = await query.AnyAsync(); var byList = await EntityFrameworkQueryableExtensions.ToListAsync(query.ToLinqToDB()); var byArray = await EntityFrameworkQueryableExtensions.ToArrayAsync(query.ToLinqToDB()); var byDictionary = await EntityFrameworkQueryableExtensions.ToDictionaryAsync(query.ToLinqToDB(), p => p.ProductId); var any = await EntityFrameworkQueryableExtensions.AnyAsync(query.ToLinqToDB()); } }
public async Task TestAsyncMethods() { using (var ctx = CreateAdventureWorksContext()) { var query = ctx.Products.AsQueryable().Where(p => p.Name.Contains("a")); var expected = await query.ToArrayAsync(); var expectedDictionary = await query.ToDictionaryAsync(p => p.ProductID); var expectedAny = await query.AnyAsync(); var byList = await EntityFrameworkQueryableExtensions.ToListAsync(query.ToLinqToDB()); var byArray = await EntityFrameworkQueryableExtensions.ToArrayAsync(query.ToLinqToDB()); var byDictionary = await EntityFrameworkQueryableExtensions.ToDictionaryAsync(query.ToLinqToDB(), p => p.ProductID); var any = await EntityFrameworkQueryableExtensions.AnyAsync(query.ToLinqToDB()); } }
public async Task <PagingResult <T> > Get(int page, int pageSize, SearchModel filter) { using (var cp = ContextProviderFactory.Create()) { IQueryable <TDb> table = cp.GetTable <TDb>().GetFilteredTable(filter, cp); TDb[] res = await EntityFrameworkQueryableExtensions.ToArrayAsync(table .Skip((page - 1) * pageSize) .Take(pageSize)); return (new PagingResult <T>() { Total = table.Count(), Items = !res.Any() ? new T[0] : DtoMapper.Map <T[]>(res), }); } }
public Task <TSource[]> ToArrayAsync <TSource>( IQueryable <TSource> source, CancellationToken cancellationToken = default) => EntityFrameworkQueryableExtensions.ToArrayAsync(source, cancellationToken);
public Task <T[]> ToArrayAsync <T>(IQueryable <T> query) { return(EntityFrameworkQueryableExtensions.ToArrayAsync(query)); }
/// <summary> /// Asynchronously loads data from query to an array. /// </summary> /// <typeparam name="TSource">Query element type.</typeparam> /// <param name="source">Source query.</param> /// <param name="token">Optional asynchronous operation cancellation token.</param> /// <returns>Array with query results.</returns> public static Task <TSource[]> ToArrayAsyncEF <TSource>( this IQueryable <TSource> source, CancellationToken token = default) => EntityFrameworkQueryableExtensions.ToArrayAsync(source, token);