示例#1
0
        public async Task <IEnumerable <TEntity> > FindAllAsync(IEnumerable <ISpecification <TEntity> > specifications, IFindOptions <TEntity> options = null, CancellationToken cancellationToken = default)
        {
            var specificationsArray = specifications as ISpecification <TEntity>[] ?? specifications.ToArray();
            var expressions         = specificationsArray.Safe()
                                      .Select(s => this.Options.Mapper.MapSpecification <TEntity, TDestination>(s));

            var result = await Task.Run(() =>
            {
                if (options?.HasOrders() == true)
                {
                    return(this.Collection.AsQueryable()
                           .WhereExpressions(expressions)
                           .OrderByIf(options, this.Options.Mapper)
                           .SkipIf(options?.Skip)
                           .TakeIf(options?.Take)
                           .ToList());
                }
                else
                {
                    return(this.Collection.AsQueryable()
                           .WhereExpressions(expressions)
                           .SkipIf(options?.Skip)
                           .TakeIf(options?.Take)
                           .ToList());
                }
            }).AnyContext();

            return(result.Select(d => this.Options.Mapper.Map <TEntity>(d)));
        }
示例#2
0
        public async Task <IEnumerable <TEntity> > FindAllAsync(
            IEnumerable <ISpecification <TEntity> > specifications,
            IFindOptions <TEntity> options      = null,
            CancellationToken cancellationToken = default)
        {
            var specificationsArray = specifications as ISpecification <TEntity>[] ?? specifications.ToArray();
            var expressions         = specificationsArray.Safe().Select(s => s.ToExpression());

            if (options?.HasOrders() == true)
            {
                return(await this.Options.DbContext.Set <TEntity>() // .AsAsyncEnumerable()
                       .TrackChangesIf(options.TrackChanges)
                       .AsExpandable()
                       .WhereExpressions(expressions)
                       .IncludeIf(options)
                       .SkipIf(options?.Skip)
                       .TakeIf(options?.Take)
                       .OrderByIf(options).ToListAsyncSafe(cancellationToken).AnyContext());
            }
            else
            {
                return(await this.Options.DbContext.Set <TEntity>() // .AsAsyncEnumerable()
                       .TrackChangesIf(options.TrackChanges)
                       .AsExpandable()
                       .WhereExpressions(expressions)
                       .IncludeIf(options)
                       .SkipIf(options?.Skip)
                       .TakeIf(options?.Take).ToListAsyncSafe(cancellationToken).AnyContext());
            }
        }
 public async Task <IEnumerable <TEntity> > FindAllAsync(IFindOptions <TEntity> options = null, CancellationToken cancellationToken = default)
 {
     if (options?.HasOrders() == true)
     {
         return(await this.options.DbContext.Set <TEntity>()
                .TakeIf(options?.Take)
                .OrderByIf(options).ToListAsyncSafe(cancellationToken).AnyContext());
     }
     else
     {
         return(await this.options.DbContext.Set <TEntity>()
                .TakeIf(options?.Take).ToListAsyncSafe(cancellationToken).AnyContext());
     }
 }