private static IPageable <T> AsPaging <T>(this ICollection <T> rows, Action <PagingDescriptor> computeAction)
            where T : class
        {
            var descriptor = new PagingDescriptor((int)rows?.Count);

            computeAction?.Invoke(descriptor);

            return(new PagingCollection <T>(rows, descriptor));
        }
Esempio n. 2
0
        public PagingCollection(ICollection <T> rows, PagingDescriptor descriptor)
        {
            rows.NotNull(nameof(rows));
            descriptor.NotNull(nameof(descriptor));

            // 如果未进行分页
            if (rows.Count > descriptor.Size)
            {
                // 手动内存分页
                _rows = rows
                        .Skip(descriptor.Skip)
                        .Take(descriptor.Size)
                        .ToList();
            }
            else
            {
                _rows = rows;
            }

            Descriptor = descriptor;
        }
        private static IPageable <TEntity> AsPagingCore <TEntity>(this IOrderedQueryable <TEntity> orderedQuery,
                                                                  Action <PagingDescriptor> computeAction)
            where TEntity : class
        {
            var descriptor = new PagingDescriptor(orderedQuery.Count());

            computeAction.Invoke(descriptor);

            IQueryable <TEntity> query = orderedQuery;

            // 跳过条数
            if (descriptor.Skip > 0)
            {
                query = query.Skip(descriptor.Skip);
            }

            // 获取条数
            if (descriptor.Size > 0)
            {
                query = query.Take(descriptor.Size);
            }

            return(new PagingCollection <TEntity>(query.ToList(), descriptor));
        }
Esempio n. 4
0
 private PagingCollection()
 {
     _rows      = Array.Empty <T>();
     Descriptor = new PagingDescriptor(0);
 }