Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

30 ms

Page Size

25

Current Page

739 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 739 Results Showing 18451 - 18475 of 24441

ID Name Category Price Stock Rating Reviews SKU
19010 Bulk Product a87c5690 Electronics $148.24 470 3.5 87 BULK-f25d83c6
19011 Bulk Product 29c83e9c Books $229.58 348 2.7 55 BULK-0801e28b
19012 Bulk Product 36e2f888 Books $305.11 293 1.0 91 BULK-4e46ead6
19013 Bulk Product bda35692 Home & Garden $381.61 102 2.0 94 BULK-7100ef8e
19014 Bulk Product d72c04f1 Sports & Outdoors $952.03 375 2.7 62 BULK-affac6d8
19015 Bulk Product b560854c Electronics $800.59 465 0.6 7 BULK-d2ddd955
19016 Bulk Product 20ff689e Sports & Outdoors $652.38 139 1.5 5 BULK-63b478f9
19017 Bulk Product 1b03aee1 Electronics $453.50 152 4.6 33 BULK-6579f320
19018 Bulk Product 1e3b125c Sports & Outdoors $231.78 243 1.7 26 BULK-f3a587c7
19019 Bulk Product 90eb7f12 Home & Garden $306.50 385 2.0 63 BULK-ade32792
19020 Bulk Product 73cfd52f Home & Garden $474.35 250 5.0 2 BULK-54571d88
19021 Bulk Product 9a0b17b9 Books $473.12 392 3.8 90 BULK-a193bcea
19022 Bulk Product 4e7bff27 Toys & Games $660.78 448 2.4 21 BULK-24db15e4
19023 Bulk Product f9042730 Clothing $945.13 28 0.4 1 BULK-8bea4db7
19024 Bulk Product b0190a40 Toys & Games $474.81 170 0.5 99 BULK-dd39fa07
19025 Bulk Product 220b4a45 Clothing $288.88 493 3.5 25 BULK-17a073d0
19026 Bulk Product 0a326dd8 Clothing $324.32 118 1.0 23 BULK-cbbd9b11
19027 Bulk Product 4541feaf Sports & Outdoors $187.96 444 2.5 2 BULK-5f000f38
19028 Bulk Product 599caddc Electronics $251.02 211 3.6 49 BULK-63da6b7e
19029 Bulk Product 02a2a468 Sports & Outdoors $575.00 496 0.8 91 BULK-c946072f
19030 Bulk Product 5d1791a7 Books $87.59 294 4.1 42 BULK-2b5478c6
19031 Bulk Product 2cda634a Toys & Games $416.45 7 2.9 82 BULK-708b5500
19032 Bulk Product a0353da6 Books $50.86 394 0.0 29 BULK-c3fc96e9
19033 Bulk Product bfceca2a Toys & Games $321.36 442 1.6 93 BULK-18dc890f
19034 Bulk Product ccf6f09c Books $305.51 407 0.6 96 BULK-8ed32b06
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