Ejemplo n.º 1
0
        public static Page <T> GetPages <T>(this Microsoft.EntityFrameworkCore.DbSet <T> list, int index_page, int page_size, Func <T, object> order_by_selector, params string[] relationsToInclude) where T : class
        {
            var result = list.IncludeMultiple(relationsToInclude).OrderBy(order_by_selector)
                         .Skip(index_page * page_size)
                         .Take(page_size)
                         .ToArray();

            var tot_items = list.Count();
            var tot_pages = tot_items / page_size;

            return(new Page <T>
            {
                Index = index_page,
                Items = result,
                TotalPages = tot_pages
            });
        }
Ejemplo n.º 2
0
        public static Page <T> GetPages <T>(this Microsoft.EntityFrameworkCore.DbSet <T> list, int index_page,
                                            int page_size, Func <T, object> order_by_selector, params string[] relationsToInclude) where T : class
        {
            var result = list.IncludeMultiple(relationsToInclude).OrderBy(order_by_selector)
                         .Skip(index_page * page_size)
                         .Take(page_size)
                         .ToArray();

            int tot_items = list.Count();
            int tot_pages = (int)(Math.Ceiling((double)tot_items / (double)page_size));

            // If there are no Items, there will still be 1 page
            if (tot_items < page_size)
            {
                tot_pages = 1;
            }

            return(new Page <T>
            {
                Index = index_page,
                Items = result,
                TotalPages = tot_pages
            });
        }