Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

50

Current Page

98 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 98 Results Showing 4851 - 4900 of 24441

ID Name Category Price Stock Rating Reviews SKU
5410 Bulk Product 219d77e9 Clothing $733.09 320 1.7 30 BULK-a201b2d8
5411 Bulk Product a50e2c7f Home & Garden $458.50 375 0.3 52 BULK-8d3faf1d
5412 Bulk Product b5b8ec77 Toys & Games $95.79 215 2.4 89 BULK-f05bbcb7
5413 Bulk Product 8a9729e4 Home & Garden $655.33 37 1.3 21 BULK-f7940ec7
5414 Bulk Product 724679b5 Clothing $983.22 247 0.5 47 BULK-7d13a698
5415 Bulk Product bc59fe93 Books $1,006.60 473 1.1 22 BULK-c3c4b63a
5416 Bulk Product f17d9fb8 Books $246.73 281 1.1 45 BULK-3a552a57
5417 Bulk Product 7def050b Home & Garden $377.66 485 4.5 31 BULK-ef47b9c4
5418 Bulk Product 7eb8a71e Sports & Outdoors $647.43 77 4.7 9 BULK-dd1604bc
5419 Bulk Product 31d3c1c8 Home & Garden $433.73 325 2.0 19 BULK-9c61ed96
5420 Bulk Product 8fa9a9f4 Books $372.11 458 3.1 18 BULK-ee793c4a
5421 Bulk Product 3abd9bc0 Home & Garden $847.58 281 2.1 73 BULK-54658aaf
5422 Bulk Product 2ec215fd Clothing $418.77 242 0.6 37 BULK-0caf7f4d
5423 Bulk Product eed6ccf1 Books $647.77 156 1.4 38 BULK-c6ac96d1
5424 Bulk Product 94519d97 Sports & Outdoors $360.38 97 3.4 1 BULK-3bc7eaad
5425 Bulk Product aa0a02d8 Sports & Outdoors $586.85 433 0.9 88 BULK-fa249bc5
5426 Bulk Product 47919b59 Electronics $588.75 255 2.7 35 BULK-7ffca7ea
5427 Bulk Product bfef71e3 Books $644.69 67 2.4 9 BULK-709ded86
5428 Bulk Product 813d302c Clothing $847.08 299 1.7 88 BULK-097f55d0
5429 Bulk Product 90294c26 Sports & Outdoors $344.29 134 3.5 25 BULK-f7707301
5430 Bulk Product d65e34a7 Toys & Games $120.37 480 3.8 32 BULK-d4dd6085
5431 Bulk Product daaf8ac3 Toys & Games $884.15 290 0.6 20 BULK-21c61884
5432 Bulk Product 0c9c5880 Clothing $770.27 416 4.3 64 BULK-19cd0cbe
5433 Bulk Product b4127d19 Home & Garden $276.83 469 0.1 22 BULK-5b0744c7
5434 Bulk Product 23e2efbe Home & Garden $494.87 184 3.5 25 BULK-307edda2
5435 Bulk Product 850f4cff Electronics $882.41 157 3.7 26 BULK-daee7cc7
5436 Bulk Product cfb0cc0a Books $642.94 310 3.8 89 BULK-c567fc3c
5437 Bulk Product fdad24e1 Clothing $484.32 415 1.9 22 BULK-ee6145c2
5438 Bulk Product 2dc10da9 Electronics $525.17 85 2.4 97 BULK-f23d0fb8
5439 Bulk Product 7a5b0b2e Books $899.33 149 3.8 23 BULK-b080d33a
5440 Bulk Product 90a87b01 Clothing $995.63 238 1.6 20 BULK-912325e5
5441 Bulk Product 9a50ad13 Home & Garden $531.50 340 1.7 71 BULK-f1389c0b
5442 Bulk Product 74096de8 Electronics $315.81 72 1.1 44 BULK-b247b7ef
5443 Bulk Product c069a315 Home & Garden $228.50 18 0.9 90 BULK-85b49cab
5444 Bulk Product a318dfeb Electronics $131.45 342 0.3 95 BULK-00b48198
5445 Bulk Product 1547f585 Toys & Games $520.35 318 2.9 52 BULK-0d294760
5446 Bulk Product 37d81441 Electronics $144.27 334 3.2 88 BULK-1fe48e13
5447 Bulk Product 756d881f Books $684.55 468 3.5 4 BULK-cfe069a9
5448 Bulk Product 77086905 Books $39.65 165 4.6 16 BULK-5852ccb3
5449 Bulk Product 11a12246 Sports & Outdoors $828.73 47 0.8 0 BULK-5baaa3f0
5450 Bulk Product 2901d37f Sports & Outdoors $106.85 257 0.7 79 BULK-7f381910
5451 Bulk Product 54a56cbb Clothing $386.60 250 4.2 93 BULK-f03d6e48
5452 Bulk Product 9a944f52 Toys & Games $167.80 327 3.5 25 BULK-1af1ec02
5453 Bulk Product 1cd59ab5 Books $183.33 175 5.0 54 BULK-da510fca
5454 Bulk Product 6b322046 Books $349.29 152 3.4 15 BULK-99b473d8
5455 Bulk Product 2de6902c Home & Garden $839.81 366 4.5 36 BULK-20bc4ae7
5456 Bulk Product e3c8e4c7 Books $72.73 175 4.1 68 BULK-6e84c72b
5457 Bulk Product 0d0de6fc Clothing $382.37 187 1.9 49 BULK-c5dc4de2
5458 Bulk Product a040046f Electronics $943.12 226 1.5 26 BULK-e295f1c0
5459 Bulk Product e343ddf1 Toys & Games $273.26 334 2.1 90 BULK-7d2bdce8
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