Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

25

Current Page

365 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 365 Results Showing 9101 - 9125 of 24441

ID Name Category Price Stock Rating Reviews SKU
9660 Bulk Product c0cda2fa Home & Garden $997.72 133 0.9 51 BULK-f990448d
9661 Bulk Product 2649d567 Sports & Outdoors $358.60 80 4.9 2 BULK-ff225fa3
9662 Bulk Product 9082164a Toys & Games $921.48 425 3.0 61 BULK-f35ca15c
9663 Bulk Product 95ee0447 Home & Garden $337.60 363 4.8 62 BULK-e547d615
9664 Bulk Product 419bf8da Electronics $221.82 496 4.8 35 BULK-520873bc
9665 Bulk Product a4ce7a39 Sports & Outdoors $699.66 373 2.9 67 BULK-be5e7bec
9666 Bulk Product dee6daaf Books $369.04 410 3.0 56 BULK-2fe6409b
9667 Bulk Product fbf680bc Home & Garden $669.36 374 4.3 3 BULK-538b3542
9668 Bulk Product 201bfd3f Books $112.46 59 1.7 42 BULK-46775746
9669 Bulk Product 2389fdc7 Home & Garden $956.68 258 3.0 55 BULK-ff152363
9670 Bulk Product 7598797c Sports & Outdoors $464.06 391 2.1 35 BULK-81496685
9671 Bulk Product 24927993 Electronics $422.38 215 0.1 54 BULK-35b2f197
9672 Bulk Product 6150bc11 Clothing $964.52 5 1.0 46 BULK-5fde6424
9673 Bulk Product 82044025 Books $800.80 497 1.8 86 BULK-0cc2597c
9674 Bulk Product 3e1e8a7f Toys & Games $36.46 145 3.1 23 BULK-a7b86bec
9675 Bulk Product 2e7b01e1 Clothing $246.56 141 0.2 73 BULK-c1cb871b
9676 Bulk Product 0d42982d Toys & Games $863.67 426 0.9 33 BULK-c8377af6
9677 Bulk Product a9fbe449 Electronics $843.86 116 3.8 1 BULK-4632d80a
9678 Bulk Product f1b0161b Books $612.39 20 3.6 43 BULK-73a683cc
9679 Bulk Product f0985e91 Books $529.34 46 2.0 84 BULK-fc913c98
9680 Bulk Product f9520895 Home & Garden $945.80 29 3.8 7 BULK-1415e702
9681 Bulk Product 518b4ed7 Home & Garden $870.24 210 3.7 65 BULK-5433bca8
9682 Bulk Product aa9545c3 Clothing $705.62 116 2.7 92 BULK-b849a5c8
9683 Bulk Product 8eea5033 Books $978.15 169 3.6 69 BULK-2999dd37
9684 Bulk Product 43de0fe0 Books $867.46 161 2.1 27 BULK-31ac7697
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