public FilteredList <Product> ReadAll(Filter filter) { var query = _ctx.Set <Product>(); if (filter == null) { return(new FilteredList <Product>() { List = _ctx.Products.ToList(), Count = _ctx.Products.Count() }); } var page = query.Select(e => e) .Skip((filter.CurrentPage - 1) * filter.ItemsPrPage) .Take(filter.ItemsPrPage) .GroupBy(e => new { Total = query.Count() }) .FirstOrDefault(); if (page != null) { var total = page.Key.Total; var items = page.Select(e => e).ToList(); return(new FilteredList <Product>() { List = items, Count = total }); } return(new FilteredList <Product>() { List = new List <Product>(), Count = 0 }); }