Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

446 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 446 Results Showing 11126 - 11150 of 24441

ID Name Category Price Stock Rating Reviews SKU
11685 Bulk Product 0378a492 Clothing $698.58 389 3.1 47 BULK-084e6f95
11686 Bulk Product 906e5a68 Electronics $455.74 291 3.9 84 BULK-d7f7ae6c
11687 Bulk Product 3cf97654 Home & Garden $907.70 182 0.1 5 BULK-d9d89660
11688 Bulk Product a87fc591 Toys & Games $744.22 23 3.6 80 BULK-d2787847
11689 Bulk Product 350e1ee5 Home & Garden $723.88 456 0.9 98 BULK-c1b49eb1
11690 Bulk Product 43f277c5 Books $566.52 447 1.3 10 BULK-0a1866e0
11691 Bulk Product a4cc15d8 Books $1,002.03 287 3.6 34 BULK-230ad96b
11692 Bulk Product f5783549 Home & Garden $239.58 488 3.5 82 BULK-6b4802b1
11693 Bulk Product 4462d9fe Home & Garden $471.25 405 2.2 81 BULK-ff5b2afc
11694 Bulk Product 10be1740 Home & Garden $806.31 88 2.4 26 BULK-28dd6394
11695 Bulk Product 1638fb70 Books $980.17 350 2.3 25 BULK-1aa2f228
11696 Bulk Product 107933fd Toys & Games $224.41 312 1.0 7 BULK-5357aceb
11697 Bulk Product cda7bdc6 Sports & Outdoors $361.96 296 0.8 40 BULK-d60b9aa2
11698 Bulk Product 9f0f4ba0 Clothing $61.28 36 4.0 53 BULK-837658f3
11699 Bulk Product 3a88aa47 Toys & Games $838.65 458 0.5 12 BULK-b782fc53
11700 Bulk Product f07c1412 Sports & Outdoors $415.72 328 3.4 73 BULK-e9591615
11701 Bulk Product 84bca0ee Clothing $122.04 340 1.1 45 BULK-cf29a2ba
11702 Bulk Product bbc036c5 Home & Garden $842.58 291 1.2 6 BULK-08e04c2c
11703 Bulk Product ed79b0a1 Electronics $269.83 498 1.8 93 BULK-a956b8cf
11704 Bulk Product 3efda39b Electronics $601.38 202 1.9 22 BULK-f2e8e849
11705 Bulk Product 1022ab11 Clothing $565.14 284 2.5 61 BULK-cc6f9994
11706 Bulk Product 7154dc0c Clothing $205.30 163 3.7 51 BULK-02bb990a
11707 Bulk Product da2deca3 Sports & Outdoors $522.87 96 4.8 31 BULK-bcdef278
11708 Bulk Product 752a8934 Home & Garden $651.92 17 2.0 7 BULK-3e4dc3fd
11709 Bulk Product aa0d5389 Toys & Games $863.37 274 4.3 81 BULK-24801ee1
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