public static IQueryable <TEntity> GetQuery(IQueryable <TEntity> inputQuery, ISpecyfication <TEntity> spec) { var query = inputQuery; if (spec.Criteria != null) { query = query.Where(spec.Criteria); } if (spec.OrderBy != null) { query = query.OrderBy(spec.OrderBy); } if (spec.OrderByDescending != null) { query = query.OrderByDescending(spec.OrderByDescending); } if (spec.IsPagingEnabled) { query = query.Skip(spec.Skip).Take(spec.Take); } query = spec.Includes.Aggregate(query, (current, include) => current.Include(include)); return(query); }
private IQueryable <T> ApplySpecyfication(ISpecyfication <T> spec) { return(SpecificationEvaluator <T> .GetQuery(_context.Set <T>().AsQueryable(), spec)); }
public async Task <IReadOnlyList <T> > ListAsync(ISpecyfication <T> spec) { return(await ApplySpecyfication(spec).ToListAsync()); }
public async Task <int> CountAsync(ISpecyfication <T> spec) { return(await ApplySpecyfication(spec).CountAsync()); }
public async Task <T> GetEntityWithSpec(ISpecyfication <T> spec) { return(await ApplySpecyfication(spec).FirstOrDefaultAsync()); }