Exemple #1
0
        public async Task <IEnumerable <TEntity> > SelectAllAsync(SelectOptions <TEntity> options = null)
        {
            IQueryable <TEntity> query = DbSet;

            query = ApplyOptions(query, options);
            return(await query.ToListAsync());
        }
Exemple #2
0
        private IQueryable <TEntity> ApplyOptions(IQueryable <TEntity> query, SelectOptions <TEntity> options)
        {
            if (options == null)
            {
                return(query);
            }

            if (options.OrderBy != null)
            {
                query = options.OrderBy(query);
            }

            if (options.Skip > 0)
            {
                query = query.Skip(options.Skip);
            }

            if (options.Take > 0)
            {
                query = query.Take(options.Take);
            }

            if (options.Includes?.Count > 0)
            {
                query = options.Includes.Aggregate(query, (current, include) => current.Include(include));
            }

            return(query);
        }
Exemple #3
0
 public virtual Task <TEntity> SelectByIdAsync(int id, SelectOptions <TEntity> options = null)
 {
     if (options != null)
     {
         return(SelectFirstOrDefaultAsync(e => e.Id == id, options));
     }
     return(DbSet.FindAsync(id));
 }
Exemple #4
0
        public async Task <IEnumerable <TEntity> > SelectAsync(ISpecification <TEntity> specification, SelectOptions <TEntity> options = null)
        {
            IQueryable <TEntity> query = DbSet;

            query = ApplySpecificationWithOptions(query, specification, options);
            return(await query.ToListAsync());
        }
Exemple #5
0
        public Task <IEnumerable <TEntity> > SelectAsync(Expression <Func <TEntity, bool> > predicate, SelectOptions <TEntity> options = null)
        {
            Specification <TEntity> specification = new Specification <TEntity>(predicate);

            return(SelectAsync(specification, options));
        }
Exemple #6
0
        public Task <TEntity> SelectFirstOrDefaultAsync(ISpecification <TEntity> specification, SelectOptions <TEntity> options = null)
        {
            IQueryable <TEntity> query = DbSet;

            query = ApplySpecificationWithOptions(query, specification, options);
            return(query.FirstOrDefaultAsync());
        }
Exemple #7
0
        public Task <TEntity> SelectFirstOrDefaultAsync(Expression <Func <TEntity, bool> > predicate, SelectOptions <TEntity> options = null)
        {
            Specification <TEntity> specification = new Specification <TEntity>(predicate);

            return(SelectFirstOrDefaultAsync(specification, options));
        }
Exemple #8
0
 private IQueryable <TEntity> ApplySpecificationWithOptions(IQueryable <TEntity> query, ISpecification <TEntity> specification, SelectOptions <TEntity> options)
 {
     query = ApplySpecification(query, specification);
     query = ApplyOptions(query, options);
     return(query);
 }