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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 private IQueryable <T> ApplySpecification(ISpecifcation <T> spec)
 {
     return(SpecificationEvaluator <T> .GetQuery(_context.Set <T>().AsQueryable(), spec));
 }
Пример #4
0
 public async Task <int> CountAsync(ISpecifcation <T> spec)
 {
     return(await ApplySpecification(spec).CountAsync());
 }
Пример #5
0
 public async Task <IReadOnlyList <T> > ListAsync(ISpecifcation <T> spec)
 {
     return(await ApplySpecification(spec).ToListAsync());
 }
Пример #6
0
 public async Task <T> GetEntityWithSpec(ISpecifcation <T> spec)
 {
     return(await ApplySpecification(spec).FirstOrDefaultAsync());
 }
Пример #7
0
 public List <GuestbookEntry> ListEntries(ISpecifcation <GuestbookEntry> spec)
 {
     return(_dbContext.Entries
            .Where(spec.Criteria)
            .ToList());
 }