Esempio n. 1
0
 public static IFetchSpecification <T> ThenByDescending <T>(
     this IFetchSpecification <T> specification,
     Expression <Func <T, object> > keySelector)
 {
     return(specification
            .ThenBy(OrderingDirection.Descending, keySelector));
 }
Esempio n. 2
0
 public static IFetchSpecification <T> TakePage <T>(
     this IFetchSpecification <T> specification,
     int pageNumber,
     int pageSize)
 {
     return(specification
            .TakePage(new PaginationExpression(pageSize, pageNumber)));
 }
Esempio n. 3
0
 public IEnumerable <TEntity> Find(
     ISpecification <TEntity>?specification           = null,
     IFetchSpecification <TEntity>?fetchSpecification = null)
 {
     return(_dbSet
            .Evaluate(specification)
            .EvaluateFetch(fetchSpecification));
 }
Esempio n. 4
0
        public static IFetchSpecification <T> ThenInclude <T, TPreviousProperty, TProperty>(
            this IFetchSpecification <T> specification,
            Expression <Func <TPreviousProperty, TProperty> > keySelector)
        {
            var lastInclude = specification.Include.Last();

            ((IncludeExpression <T>)lastInclude).ThenInclude(keySelector);
            return(specification);
        }
Esempio n. 5
0
 public static IFetchSpecification <T> WithNoOrder <T>(
     this IFetchSpecification <T> specification)
 {
     return(new FetchSpecification <T>
            (
                include: specification.Include,
                orderBy: null,
                takePage: specification.TakePage
            ));
 }
Esempio n. 6
0
 private static IFetchSpecification <T> TakePage <T>(
     this IFetchSpecification <T> specification,
     PaginationExpression?takePage)
 {
     return(new FetchSpecification <T>
            (
                include: specification.Include,
                orderBy: specification.OrderBy,
                takePage: takePage
            ));
 }
Esempio n. 7
0
 private static IFetchSpecification <T> OrderBy <T>(
     this IFetchSpecification <T> specification,
     OrderingDirection direction,
     Expression <Func <T, object> > keySelector)
 {
     return(new FetchSpecification <T>
            (
                include: specification.Include,
                orderBy: new[] { new OrderingExpression <T>(direction, keySelector), },
                takePage: specification.TakePage
            ));
 }
Esempio n. 8
0
        private static IFetchSpecification <T> ThenBy <T>(
            this IFetchSpecification <T> specification,
            OrderingDirection direction,
            Expression <Func <T, object> > keySelector)
        {
            var orderBy = specification.OrderBy.ToList();

            orderBy.Add(new OrderingExpression <T>(direction, keySelector));

            return(new FetchSpecification <T>
                   (
                       include: specification.Include,
                       orderBy: orderBy,
                       takePage: specification.TakePage
                   ));
        }
Esempio n. 9
0
        internal static IQueryable <TEntity> EvaluateFetch <TEntity>(
            this IQueryable <TEntity> query,
            IFetchSpecification <TEntity>?specification)
            where TEntity : class
        {
            if (specification == null)
            {
                return(query);
            }

            foreach (var includeExpression in specification.Include)
            {
                query = (IQueryable <TEntity>)includeExpression.AddIncludes(query);
            }

            for (var i = 0; i < specification.OrderBy.Count; i++)
            {
                var(direction, keySelector) = specification.OrderBy[i];

                switch (direction)
                {
                case OrderingDirection.Ascending:
                    query = i == 0
                            ? query.OrderBy(keySelector)
                            : ((IOrderedQueryable <TEntity>)query).ThenBy(keySelector);
                    break;

                case OrderingDirection.Descending:
                    query = i == 0
                            ? query.OrderByDescending(keySelector)
                            : ((IOrderedQueryable <TEntity>)query).ThenByDescending(keySelector);
                    break;
                }
            }

            if (specification.TakePage != null)
            {
                var(pageSize, pageIndex) = specification.TakePage;

                query = query
                        .Skip(pageSize * pageIndex)
                        .Take(pageSize);
            }

            return(query);
        }
Esempio n. 10
0
        public static IFetchSpecification <T> Include <T, TProperty>(
            this IFetchSpecification <T> specification,
            Expression <Func <T, TProperty> > keySelector)
        {
            var includes = new List <IIncludeExpression <T> >();

            if (specification.Include.Any())
            {
                includes.AddRange(specification.Include);
            }
            var includeExpr = new IncludeExpression <T>();

            includeExpr.Include <T, TProperty>(keySelector);
            includes.Add(includeExpr);
            return(new FetchSpecification <T>
                   (
                       include: includes,
                       orderBy: specification.OrderBy,
                       takePage: specification.TakePage
                   ));
        }
Esempio n. 11
0
 public static IFetchSpecification <T> TakeAll <T>(
     this IFetchSpecification <T> specification)
 {
     return(specification
            .TakePage(null));
 }
Esempio n. 12
0
 public IEnumerable <TEntity> Find(
     ISpecification <TEntity>?specification           = null,
     IFetchSpecification <TEntity>?fetchSpecification = null)
 {
     throw new NotImplementedException();
 }