public Task <TEntity> GetFirstOrDefaultAsync(QueryableExpressionSpecification <TEntity> specification = null,
                                                     bool disableTracking = true)
        {
            var query = GetQuery(disableTracking, specification);

            return(specification?.OrderBy?.Invoke(query).FirstOrDefaultAsync() ?? query.FirstOrDefaultAsync());
        }
        public Task <TResult> GetFirstOrDefaultAsync <TResult>(Expression <Func <TEntity, TResult> > selector,
                                                               QueryableExpressionSpecification <TEntity> specification = null,
                                                               bool disableTracking = true)
        {
            var query = GetQuery(disableTracking, specification);

            return(specification?.OrderBy != null
                ? specification.OrderBy(query).Select(selector).FirstOrDefaultAsync()
                : query.Select(selector).FirstOrDefaultAsync());
        }
        public IPagedList <TEntity> GetPagedList(QueryableExpressionSpecification <TEntity> specification = null,
                                                 int pageIndex        = 0,
                                                 int pageSize         = 20,
                                                 bool disableTracking = true)
        {
            var query = GetQuery(disableTracking, specification);

            return(specification?.OrderBy?.Invoke(query).ToPagedList(pageIndex, pageSize) ??
                   query.ToPagedList(pageIndex, pageSize));
        }
        public IPagedList <TResult> GetPagedList <TResult>(Expression <Func <TEntity, TResult> > selector,
                                                           QueryableExpressionSpecification <TEntity> specification = null,
                                                           int pageIndex        = 0,
                                                           int pageSize         = 20,
                                                           bool disableTracking = true)
            where TResult : class
        {
            var query = GetQuery(disableTracking, specification);

            return(specification?.OrderBy?.Invoke(query).Select(selector).ToPagedList(pageIndex, pageSize) ??
                   query.Select(selector).ToPagedList(pageIndex, pageSize));
        }
        public Task <IPagedList <TEntity> > GetPagedListAsync(
            QueryableExpressionSpecification <TEntity> specification = null,
            int pageIndex        = 0,
            int pageSize         = 20,
            bool disableTracking = true,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var query = GetQuery(disableTracking, specification);

            return(specification?.OrderBy?.Invoke(query).ToPagedListAsync(pageIndex, pageSize, 0, cancellationToken) ??
                   query.ToPagedListAsync(pageIndex, pageSize, 0, cancellationToken));
        }
        public Task <IPagedList <TResult> > GetPagedListAsync <TResult>(Expression <Func <TEntity, TResult> > selector,
                                                                        QueryableExpressionSpecification <TEntity> specification = null,
                                                                        int pageIndex        = 0,
                                                                        int pageSize         = 20,
                                                                        bool disableTracking = true,
                                                                        CancellationToken cancellationToken = default(CancellationToken))
            where TResult : class
        {
            var query = GetQuery(disableTracking, specification);

            return(specification?.OrderBy?.Invoke(query).Select(selector)
                   .ToPagedListAsync(pageIndex, pageSize, 0, cancellationToken) ?? query.Select(selector)
                   .ToPagedListAsync(pageIndex, pageSize, 0, cancellationToken));
        }
        public static Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > GetOrderByExpression <TEntity>(
            QueryableExpressionSpecification <TEntity> leftExpressionSpecification,
            QueryableExpressionSpecification <TEntity> rightExpressionSpecification)
        {
            var isLeftExpressionSpecificationOrderByDefined  = leftExpressionSpecification.OrderBy != null;
            var isRightExpressionSpecificationOrderByDefined = rightExpressionSpecification.OrderBy != null;

            if (isLeftExpressionSpecificationOrderByDefined && isRightExpressionSpecificationOrderByDefined)
            {
                throw new SpecificationOrderByException(
                          "Cannot have two different order by for the joint specification");
            }

            if (isLeftExpressionSpecificationOrderByDefined)
            {
                return(leftExpressionSpecification.OrderBy);
            }

            return(isRightExpressionSpecificationOrderByDefined ? rightExpressionSpecification.OrderBy : null);
        }
        private IQueryable <TEntity> GetQuery(bool disableTracking,
                                              QueryableExpressionSpecification <TEntity> specification = null)
        {
            IQueryable <TEntity> query = DbSet;

            if (disableTracking)
            {
                query = query.AsNoTracking();
            }

            var includeData = specification?.Include <IIncludableQueryable <TEntity, object> >();

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

            if (specification?.ToExpression() != null)
            {
                query = query.Where(specification.ToExpression());
            }

            return(query);
        }
Example #9
0
 public AndExpressionSpecification(QueryableExpressionSpecification <TEntity> leftExpressionSpecification,
                                   QueryableExpressionSpecification <TEntity> rightExpressionSpecification)
 {
     _rightExpressionSpecification = rightExpressionSpecification;
     _leftExpressionSpecification  = leftExpressionSpecification;
 }
 public static Func <IQueryable <TEntity>, IOrderedQueryable <TEntity> > GetOrderByExpression <TEntity>(
     QueryableExpressionSpecification <TEntity> expressionSpecification) => expressionSpecification.OrderBy;
 public NotExpressionSpecification(QueryableExpressionSpecification <TEntity> expressionSpecification) =>