public List <T> GetPage(int page, int resultsPerPage, string orderBy, Func <string, Expression <Func <T, object> > > map, bool desc = false, ISpecification <T> spec = null)
        {
            PagedSpecification <T> spec1 = new PagedSpecification <T>(map);

            spec1.ApplyOrderBy(orderBy, desc);
            spec1.Apply(page * resultsPerPage, resultsPerPage);
            if (spec == null)
            {
                return(base.GetPage(page, resultsPerPage,
                                    new List <ISort>()
                {
                    SpecificationEvaluator <T, TKey> .GetSort(spec1)
                }));
            }
            else
            {
                return(base.GetPage(page, resultsPerPage,
                                    new List <ISort>()
                {
                    SpecificationEvaluator <T, TKey> .GetSort(spec1)
                },
                                    SpecificationEvaluator <T, TKey> .GetQuery(spec)));
            }
        }
示例#2
0
        public IQueryable <T> Build(IRepository repository)
        {
            IQueryable <T> query;

            if (_include != null)
            {
                var loadService = repository.As <ILoadService <T> >().Include(_include);
                query = loadService.All();
            }
            else
            {
                query = repository.All <T>();
            }

            if (_query != null && _pageNumber != 0 && _pageSize != 0)
            {
                var paging = new PagedSpecification <T>((Specification <T>)_query).Page(_pageNumber, _pageSize);
                query = paging.Apply(query);
            }
            else if (_query != null)
            {
                query = _query.Apply(query);
            }
            else if (_pageNumber != 0 && _pageSize != 0)
            {
                var paging = new PagedSpecification <T>(Specification <T> .AlwaysTrue).Page(_pageNumber, _pageSize);
                query = paging.Apply(query);
            }

            if (_orderBy != null)
            {
                query = _orderBy.Apply(query);
            }

            return(query);
        }