Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

90 ms

Page Size

25

Current Page

779 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 779 Results Showing 19451 - 19475 of 24441

ID Name Category Price Stock Rating Reviews SKU
20010 Bulk Product 59b45cf6 Books $406.73 146 1.2 80 BULK-4e83a779
20011 Bulk Product 32a93b7f Electronics $641.67 201 3.3 99 BULK-bbfd60eb
20012 Bulk Product c0e309e1 Books $860.58 365 2.3 97 BULK-3bafdf7b
20013 Bulk Product f0b04f70 Toys & Games $510.37 172 1.0 55 BULK-ad70b551
20014 Bulk Product 64d6f772 Sports & Outdoors $215.08 321 4.0 89 BULK-8f39ac87
20015 Bulk Product ba49152d Toys & Games $251.58 38 1.7 0 BULK-ab3f98b5
20016 Bulk Product 30e88ba3 Toys & Games $803.93 37 3.7 73 BULK-bdc89d0b
20017 Bulk Product f8632bff Sports & Outdoors $901.27 372 4.0 33 BULK-023448d3
20018 Bulk Product edb54000 Home & Garden $891.94 465 1.2 62 BULK-21d4d383
20019 Bulk Product 706472a2 Sports & Outdoors $946.49 275 4.1 64 BULK-d4f39e46
20020 Bulk Product f05b5e89 Toys & Games $295.20 105 4.9 51 BULK-1c3c37a3
20021 Bulk Product 16292e23 Electronics $348.15 377 1.3 38 BULK-d8f46b9d
20022 Bulk Product 21a8e327 Sports & Outdoors $567.37 25 0.4 52 BULK-2a695a96
20023 Bulk Product 64f4a844 Home & Garden $475.08 253 0.5 95 BULK-ddf2e7b7
20024 Bulk Product e896dcf7 Books $193.78 499 2.8 86 BULK-e0d0bf17
20025 Bulk Product b644b044 Toys & Games $40.68 130 1.6 16 BULK-b76d6c6a
20026 Bulk Product 005e6b03 Electronics $924.06 36 0.3 30 BULK-b55767d3
20027 Bulk Product 7f367388 Electronics $334.44 388 3.8 37 BULK-7e70d31d
20028 Bulk Product c2d1db40 Toys & Games $673.59 405 2.2 15 BULK-ea99e69a
20029 Bulk Product 40623046 Toys & Games $278.55 261 3.4 90 BULK-2cbb0dc7
20030 Bulk Product 1c21b3c3 Toys & Games $447.27 465 1.1 18 BULK-e71c816d
20031 Bulk Product 9a100e55 Electronics $260.30 358 0.8 1 BULK-87430b2c
20032 Bulk Product 5efe76d6 Electronics $628.62 196 0.2 16 BULK-1f3a5a11
20033 Bulk Product ef183c66 Home & Garden $647.04 363 0.0 76 BULK-8484bd27
20034 Bulk Product 5ed2e578 Books $636.95 349 4.2 91 BULK-901c279c
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