Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

61 ms

Page Size

25

Current Page

67 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 67 Results Showing 1651 - 1675 of 24441

ID Name Category Price Stock Rating Reviews SKU
1865 Mega Electronics Product Mini Electronics $286.40 465 3.4 591 SKU-001865
1866 Professional Clothing Product Advanced Clothing $464.23 49 4.5 642 SKU-001866
1867 Standard Food & Grocery Product 2024 Food & Grocery $132.84 352 1.1 739 SKU-001867
1868 Standard Office Supplies Product Classic Office Supplies $508.29 309 1.6 68 SKU-001868
1869 Economy Automotive Product Max Automotive $859.60 135 1.2 61 SKU-001869
1870 Super Toys & Games Product Max Toys & Games $857.96 337 3.1 399 SKU-001870
1871 Economy Clothing Product Special Edition Clothing $874.61 78 2.1 587 SKU-001871
1873 Premium Clothing Product Max Clothing $522.81 300 4.4 864 SKU-001873
1874 Economy Office Supplies Product Special Edition Office Supplies $46.09 16 2.5 775 SKU-001874
1875 Premium Home & Garden Product XL Home & Garden $900.13 51 1.2 611 SKU-001875
1876 Premium Health & Beauty Product Classic Health & Beauty $269.65 330 4.9 207 SKU-001876
1878 Deluxe Health & Beauty Product Pro Health & Beauty $385.11 388 2.2 420 SKU-001878
1879 Standard Toys & Games Product XL Toys & Games $810.73 25 1.5 827 SKU-001879
1880 Pro Automotive Product 2024 Automotive $921.95 397 1.6 7 SKU-001880
1881 Elite Electronics Product XL Electronics $743.37 225 4.1 337 SKU-001881
1882 Elite Health & Beauty Product Max Health & Beauty $577.11 368 2.1 903 SKU-001882
1883 Deluxe Home & Garden Product Plus Home & Garden $463.14 350 1.8 153 SKU-001883
1884 Premium Health & Beauty Product Pro Health & Beauty $914.88 160 3.0 228 SKU-001884
1885 Standard Sports & Outdoors Product Max Sports & Outdoors $495.82 491 2.2 631 SKU-001885
1886 Standard Health & Beauty Product Classic Health & Beauty $679.29 420 1.6 675 SKU-001886
1887 Deluxe Health & Beauty Product XL Health & Beauty $992.16 207 1.6 515 SKU-001887
1888 Premium Food & Grocery Product Mini Food & Grocery $952.85 122 2.9 605 SKU-001888
1889 Super Books Product Special Edition Books $724.75 491 3.4 775 SKU-001889
1890 Deluxe Clothing Product 2024 Clothing $840.67 373 1.1 334 SKU-001890
1891 Super Food & Grocery Product Plus Food & Grocery $573.89 11 2.8 565 SKU-001891
Implementation Code
// Efficient pagination with Skip and Take
public async Task<PaginatedResult<DemoProduct>> GetPaginatedProductsAsync(int page, int pageSize)
{
    // Get total count (cached if possible)
    var totalCount = await _context.DemoProducts.CountAsync(p => p.IsActive);
    
    // Get page of results
    var items = await _context.DemoProducts
        .Where(p => p.IsActive)
        .OrderBy(p => p.Id) // Important: Must have ORDER BY for consistent paging
        .Skip((page - 1) * pageSize) // OFFSET in SQL
        .Take(pageSize) // FETCH NEXT in SQL
        .AsNoTracking() // No tracking needed for read-only
        .ToListAsync();

    return new PaginatedResult<DemoProduct>
    {
        Items = items,
        TotalCount = totalCount,
        Page = page,
        PageSize = pageSize
    };
}
Pagination Best Practices
  • Always use OrderBy: Skip/Take require stable sorting for consistent results
  • Use AsNoTracking(): Pagination queries are typically read-only
  • Consider caching: Cache total count if dataset changes infrequently
  • Limit max page size: Prevent users from requesting too many records at once
  • Use indexed columns: Ensure ORDER BY columns are indexed for performance