public static IQueryable <TEntity> GetQuery(IQueryable <TEntity> inputQuery, ISpecifcation <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); }
public static IQueryable <TEntity> GetQueryable(IQueryable <TEntity> inputQuery, ISpecifcation <TEntity> specifcation) { if (specifcation.Criteria != null) { inputQuery = inputQuery.Where(specifcation.Criteria); } if (specifcation.OrderBy != null) { inputQuery = inputQuery.OrderBy(specifcation.OrderBy); } if (specifcation.OrderByDesc != null) { inputQuery = inputQuery.OrderByDescending(specifcation.OrderByDesc); } if (specifcation.PagingEnable) { inputQuery = inputQuery.Skip(specifcation.Skip).Take(specifcation.Take); } inputQuery = specifcation.Includes.Aggregate(inputQuery, (current, include) => current.Include(include)); return(inputQuery); }
private IQueryable <T> ApplySpecification(ISpecifcation <T> spec) { return(SpecificationEvaluator <T> .GetQuery(_context.Set <T>().AsQueryable(), spec)); }
public async Task <int> CountAsync(ISpecifcation <T> spec) { return(await ApplySpecification(spec).CountAsync()); }
public async Task <IReadOnlyList <T> > ListAsync(ISpecifcation <T> spec) { return(await ApplySpecification(spec).ToListAsync()); }
public async Task <T> GetEntityWithSpec(ISpecifcation <T> spec) { return(await ApplySpecification(spec).FirstOrDefaultAsync()); }
public List <GuestbookEntry> ListEntries(ISpecifcation <GuestbookEntry> spec) { return(_dbContext.Entries .Where(spec.Criteria) .ToList()); }