Пример #1
0
        public async Task <List <T> > FindAllAsync(
            params string[] includeProperties)
        {
            IQueryable <T> query = _dbSet.AsNoTracking();

            query = query.AddIncludes(includeProperties);

            return(await query.ToListAsync());
        }
Пример #2
0
        public async Task <T> FirstOrDefaultAsync(Expression <Func <T, bool> > filter = null, params string[] includeProperties)
        {
            IQueryable <T> query = _dbSet.AsNoTracking();

            if (filter != null)
            {
                query = query.Where(filter);
            }

            query = query.AddIncludes(includeProperties);

            return(await query.FirstOrDefaultAsync());
        }
Пример #3
0
        public void ShouldAddNestedIncludes()
        {
            IQueryable <Product> query = _context.Product.AddWheres(p => p.ProductModelId == 7);

            query = query.AddIncludes(
                p => p.Include(x => x.ProductModel).ThenInclude(x => x.ProductModelIllustration),
                p => p.Include(x => x.ProductInventory).ThenInclude(x => x.Location));

            var prod = query.First();

            Assert.NotNull(prod.ProductModel);
            Assert.NotNull(prod.ProductModel.ProductModelIllustration);
            Assert.NotEmpty(prod.ProductModel.ProductModelIllustration);
        }
Пример #4
0
        public async Task <List <T> > FindAsync(
            Expression <Func <T, bool> > filter = null,
            Func <IQueryable <T>, IOrderedQueryable <T> > orderBy = null,
            int skip = 0,
            int take = 0,
            params string[] includeProperties)
        {
            if (skip < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(skip));
            }

            if (take < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(take));
            }

            IQueryable <T> query = _dbSet.AsNoTracking();

            if (filter != null)
            {
                query = query.Where(filter);
            }

            if (orderBy != null)
            {
                query = orderBy(query);
            }

            if (skip != 0)
            {
                query = query.Skip(skip);
            }

            if (take != 0)
            {
                query = query.Take(take);
            }

            query = query.AddIncludes(includeProperties);

            return(await query.ToListAsync());
        }