Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

39 ms

Page Size

25

Current Page

608 / 978

Total Records

24441

Items per page: 25 50 100 200

Page 608 Results Showing 15176 - 15200 of 24441

ID Name Category Price Stock Rating Reviews SKU
15735 Bulk Product 2ca568e1 Books $907.50 424 4.8 40 BULK-997f178e
15736 Bulk Product aacd9d6d Electronics $874.98 8 5.0 40 BULK-3b16341e
15737 Bulk Product 9e4fe4ab Clothing $751.04 70 1.3 73 BULK-47c92c09
15738 Bulk Product 9162985b Home & Garden $625.68 269 0.7 8 BULK-ef8f43ae
15739 Bulk Product b61cb9d7 Home & Garden $60.17 496 4.5 44 BULK-d932a64e
15740 Bulk Product 882d78dd Home & Garden $911.76 337 4.2 62 BULK-fb813f49
15741 Bulk Product d3473168 Electronics $343.82 330 0.4 59 BULK-2ecc8362
15742 Bulk Product b8577724 Sports & Outdoors $703.62 478 2.8 54 BULK-293300ef
15743 Bulk Product 26313716 Home & Garden $744.36 173 2.5 48 BULK-a111fb3f
15744 Bulk Product 0f0f0a3c Electronics $891.09 249 1.8 93 BULK-2c4cb444
15745 Bulk Product ca73873c Clothing $495.32 129 2.7 34 BULK-cd572746
15746 Bulk Product 925ca212 Books $485.71 134 0.5 66 BULK-714d2099
15747 Bulk Product db2c8825 Electronics $247.03 480 1.2 47 BULK-840fadaf
15748 Bulk Product a25930a8 Books $548.22 436 3.1 19 BULK-fb3c7682
15749 Bulk Product 1222e18c Sports & Outdoors $572.03 85 4.9 71 BULK-87087692
15750 Bulk Product f3a07a9b Books $369.25 338 0.2 6 BULK-4ce5f360
15751 Bulk Product 159463e4 Home & Garden $527.20 23 1.7 62 BULK-a9e53e6d
15752 Bulk Product 4073dba3 Home & Garden $437.63 185 4.9 33 BULK-df842074
15753 Bulk Product a12b3b7f Sports & Outdoors $81.85 337 2.6 86 BULK-e686ba6e
15754 Bulk Product 0eadd2a7 Electronics $831.49 463 2.1 53 BULK-8318a857
15755 Bulk Product 19c98c20 Electronics $642.79 402 0.6 82 BULK-8cce2798
15756 Bulk Product 135305ab Home & Garden $954.09 82 1.6 22 BULK-2331ccf8
15757 Bulk Product 2f4c0d92 Home & Garden $228.47 69 0.9 41 BULK-e537724c
15758 Bulk Product 0cee9164 Books $339.34 261 4.0 79 BULK-f7596406
15759 Bulk Product c59dacea Home & Garden $348.14 150 0.5 33 BULK-8a89cc16
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