Exemplo n.º 1
0
    public static Page <T> GetPage <T>(this Microsoft.EntityFrameworkCore.DbSet <T> List, int page_index, int page_size, Func <T, object> order_by_selector)
        where T : class
    {
        var res = List.OrderBy(order_by_selector)
                  .Skip(page_index * page_size)
                  .Take(page_size)
                  .ToArray();

        if (res == null || res.Length == 0)
        {
            return(null);
        }

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

        if (tot_items < page_size)
        {
            tot_pages = 1;
        }

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