Example #1
0
        public static PageableResult <TSource> Page <TSource>(
            this IQueryable <TSource> source, Pageable query)
            where TSource : class
        {
            var count = source.Count();

            if (string.IsNullOrWhiteSpace(query.OrderBy))
            {
                query.OrderBy = "Id";
            }
            var items = source.OrderBy(query.OrderBy, query.IsDesc)
                        .Skip(query.PageSize * (query.PageIndex - 1))
                        .Take(query.PageSize)
                        .ToList();
            var pagedList = new PageableResult <TSource>(query.PageIndex, query.PageSize, count, items);

            return(pagedList);
        }
Example #2
0
        public static IQueryable <TEntity> Page <TEntity, TPrimary>(this IQueryable <TEntity> source, Pageable query, PageableResult pageableResult) where TEntity : Entity <TPrimary>
        {
            pageableResult.TotalCount = source.Count();

            if (string.IsNullOrWhiteSpace(query.OrderBy))
            {
                query.OrderBy = "Id";
            }

            return(source.OrderBy(query.OrderBy, query.IsDesc)
                   .Skip(query.PageSize * (query.PageIndex - 1))
                   .Take(query.PageSize));
        }