Ejemplo n.º 1
0
        public static IOrderedQueryable <TEntity> OrderBySpecification <TEntity>(
            this IQueryable <TEntity> query,
            IOrderBySpecification <TEntity> orderBy)
            where TEntity : class
        {
            Guard.Against <ArgumentNullException>(query == null, "query");
            Guard.Against <ArgumentNullException>(orderBy == null, "orderBy");

            return(orderBy.ApplyOrderBy(query));
        }
Ejemplo n.º 2
0
        public PagedElements <TEntity> GetPagedElements(
            int pageIndex,
            int pageSize,
            ISpecification <TEntity> specification,
            IOrderBySpecification <TEntity> orderBySpecification
            )
        {
            // checking arguments for this query
            Guard.Against <ArgumentException>(pageIndex < 0, "pageIndex");
            Guard.Against <ArgumentException>(pageSize <= 0, "pageSize");
            Guard.IsNotNull(orderBySpecification, "orderBySpecification");
            Guard.IsNotNull(specification, "specification");

            this.logger.Debug(
                string.Format(
                    CultureInfo.InvariantCulture,
                    "Getting paged elements {0}, pageIndex: {1}, pageSize {2}, oderBy {3}",
                    typeof(TEntity).Name,
                    pageIndex,
                    pageSize,
                    orderBySpecification.ToString()));

            // Create associated IObjectSet and perform query
            var objectSet = this.Query();

            IQueryable <TEntity> query = objectSet.Where(specification.IsSatisfiedBy());
            int total = query.Count();

            return(new PagedElements <TEntity>(
                       query
                       .OrderBySpecification(orderBySpecification)
                       .Skip(pageIndex * pageSize)
                       .Take(pageSize)
                       .ToList(),
                       total));
        }