public async Task <TEntity> GetWithSpesificationAsync(ISpesification <TEntity> spesification)
        {
            using var context = new ProductContext();
            var query = ApplySpesification(context, spesification);

            return(await query.FirstOrDefaultAsync());
        }
        public async Task <List <TEntity> > GetListWithSpesificationAsync(ISpesification <TEntity> spesification)
        {
            using var context = new ProductContext();
            var query = ApplySpesification(context, spesification);

            return(await query.ToListAsync());
        }
        public static IQueryable <TEntity> GetQuery(IQueryable <TEntity> inputQuery, ISpesification <TEntity> spesification)
        {
            var query = inputQuery;

            if (spesification.Criteria != null)
            {
                query = query.Where(spesification.Criteria);
            }
            query = spesification.Includes.Aggregate(query, (current, include) => current.Include(include));
            return(query);
        }
Пример #4
0
        public static IQueryable <TEntity> GetQuery(IQueryable <TEntity> inputQuery, ISpesification <TEntity> spesification)
        {
            var query = inputQuery;

            if (spesification.Criteria != null)
            {
                query = query.Where(spesification.Criteria); // p => p.ProductTypeId == id
            }
            if (spesification.OrderBy != null)
            {
                query = query.OrderBy(spesification.OrderBy); // p => p.ProductTypeId == id
            }
            if (spesification.OrderByDescending != null)
            {
                query = query.OrderByDescending(spesification.OrderByDescending); // p => p.ProductTypeId == id
            }
            if (spesification.IsPagingEnabled)
            {
                query = query.Skip(spesification.Skip).Take(spesification.Take);
            }

            query = spesification.Includes.Aggregate(query, (current, include) => current.Include(include));
            return(query);
        }
        public static IQueryable <TEntiy> GetQuery(IQueryable <TEntiy> inputQuery, ISpesification <TEntiy> spec)
        {
            var query = inputQuery;

            if (spec.Creteria != null)
            {
                query = query.Where(spec.Creteria);
            }
            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 <TEntity> ApplySpesification(ProductContext context, ISpesification <TEntity> spesification)
 {
     return(SpesificationEvaulator <TEntity> .GetQuery(context.Set <TEntity>().AsQueryable(), spesification));
 }
Пример #7
0
 private IQueryable <T> ApplySpesification(ISpesification <T> spec)
 {
     return(SpesificationEvaluator <T> .GetQuery(_context.Set <T>().AsQueryable(), spec));
 }
Пример #8
0
 public async Task <IReadOnlyList <T> > ListAsync(ISpesification <T> spec)
 {
     return(await ApplySpesification(spec).ToListAsync());
 }
Пример #9
0
 public async Task <T> GetEntityWithSpec(ISpesification <T> spec)
 {
     return(await ApplySpesification(spec).FirstOrDefaultAsync());
 }
Пример #10
0
 public async Task <int> CountAsync(ISpesification <TEntity> spec)
 {
     return(await ApplySpesification(spec).CountAsync());
 }
Пример #11
0
 private IQueryable <TEntity> ApplySpesification(ISpesification <TEntity> spec)
 {
     return(SpesificationEveluator <TEntity> .GetQuery(_ctx.Set <TEntity>().AsQueryable(), spec));
 }
        public async Task <TEntity> GetWithSpecQuery(ISpesification <TEntity> spesification)
        {
            var query = ApplySpesification(spesification);

            return(await query.FirstOrDefaultAsync());
        }
        private IQueryable <TEntity> ApplySpesification(ISpesification <TEntity> spesification)
        {
            var context = new TContext();

            return(SpesificationEvaulator <TEntity> .GetQuery(context.Set <TEntity>().AsQueryable(), spesification));
        }
        public async Task <List <TEntity> > GetListWithSpecQuery(ISpesification <TEntity> spesification)
        {
            var query = ApplySpesification(spesification);

            return(await query.ToListAsync());
        }