Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

50

Current Page

420 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 420 Results Showing 20951 - 21000 of 24441

ID Name Category Price Stock Rating Reviews SKU
21510 Bulk Product 53d0ea97 Sports & Outdoors $245.65 54 3.7 47 BULK-2e0c6281
21511 Bulk Product 5d899ea4 Clothing $152.25 206 3.1 2 BULK-4d84b830
21512 Bulk Product eff38c7f Clothing $937.16 182 4.6 2 BULK-41d74577
21513 Bulk Product 1c1fdc44 Clothing $72.35 61 1.6 75 BULK-16694b51
21514 Bulk Product b1b8b313 Sports & Outdoors $174.58 181 5.0 73 BULK-c51ed80a
21515 Bulk Product 4ee5d697 Home & Garden $583.78 266 4.5 16 BULK-fd0fbaf8
21516 Bulk Product 0c13dd50 Books $457.15 189 2.6 48 BULK-6f48548b
21517 Bulk Product 1c014480 Home & Garden $667.53 86 4.6 77 BULK-15747a71
21518 Bulk Product 1ba2b5ec Toys & Games $362.09 62 1.2 74 BULK-eea999bf
21519 Bulk Product b02dc82b Home & Garden $552.56 184 1.7 30 BULK-0881c12a
21520 Bulk Product a47e0b51 Electronics $232.95 309 3.8 24 BULK-a2c4f69e
21521 Bulk Product eb170f0e Home & Garden $264.91 351 0.0 67 BULK-036d058a
21522 Bulk Product 00cd40ab Clothing $488.86 480 3.7 53 BULK-0c200c36
21523 Bulk Product 9478d7a4 Sports & Outdoors $576.51 117 0.7 79 BULK-fca564e6
21524 Bulk Product a95b1943 Toys & Games $638.23 460 4.3 36 BULK-ecd551ac
21525 Bulk Product b982bc9e Clothing $20.63 434 3.0 0 BULK-5235c3eb
21526 Bulk Product 5e039197 Sports & Outdoors $669.25 25 1.0 43 BULK-cbe222f1
21527 Bulk Product 2b3d4e4e Sports & Outdoors $952.76 250 4.0 43 BULK-006a6f17
21528 Bulk Product a8797c71 Toys & Games $281.36 432 2.0 18 BULK-a0c50d4c
21529 Bulk Product ac18137a Home & Garden $841.45 103 0.5 84 BULK-773a1a97
21530 Bulk Product b0f43df3 Toys & Games $618.70 493 0.3 37 BULK-7f83c961
21531 Bulk Product 2580c7ca Electronics $432.00 420 0.4 2 BULK-6d509ec8
21532 Bulk Product 1fc4c4a2 Clothing $994.49 455 1.5 32 BULK-c1422fbf
21533 Bulk Product f7ca4ede Toys & Games $831.66 486 2.6 59 BULK-c5689e2c
21534 Bulk Product 7cbd5991 Sports & Outdoors $687.63 274 4.8 42 BULK-ce8d9279
21535 Bulk Product 7e3040b2 Toys & Games $628.68 93 2.0 52 BULK-8697795e
21536 Bulk Product 9eb21074 Books $977.16 164 3.0 52 BULK-57df274a
21537 Bulk Product fdff2268 Home & Garden $198.50 90 1.9 70 BULK-81e70ffb
21538 Bulk Product f62db69a Home & Garden $414.95 393 2.5 24 BULK-0055a82d
21539 Bulk Product 4be5f5f6 Clothing $574.97 3 1.9 41 BULK-5c93dc97
21540 Bulk Product e867ffa6 Clothing $92.38 355 2.9 85 BULK-66eba215
21541 Bulk Product 699dc47b Books $736.12 299 4.1 84 BULK-50cd22f3
21542 Bulk Product 8619dba9 Sports & Outdoors $293.88 23 0.4 63 BULK-d0e8dc29
21543 Bulk Product 35857f44 Books $756.07 431 2.4 19 BULK-44df593c
21544 Bulk Product 73c2276c Books $762.07 265 4.1 21 BULK-cf731247
21545 Bulk Product 004f9578 Toys & Games $29.00 148 2.8 8 BULK-d9482ad1
21546 Bulk Product d7421e1e Home & Garden $228.42 321 2.7 66 BULK-317cb7f0
21547 Bulk Product ef9b50f6 Clothing $577.70 371 3.3 88 BULK-935860ce
21548 Bulk Product 207e811b Books $332.72 178 2.2 88 BULK-9c0bf517
21549 Bulk Product 0ff64d98 Electronics $338.82 240 2.9 93 BULK-4451d025
21550 Bulk Product 187a7bc9 Toys & Games $599.39 340 3.2 41 BULK-cf0ce3a8
21551 Bulk Product 7982c05c Sports & Outdoors $82.37 294 0.1 60 BULK-99380819
21552 Bulk Product 9a5394ec Clothing $284.62 355 3.6 52 BULK-804a7e46
21553 Bulk Product 0578be83 Electronics $303.89 72 1.6 31 BULK-77534a13
21554 Bulk Product 8941b129 Toys & Games $854.59 382 0.3 68 BULK-619e5961
21555 Bulk Product 13ee27c3 Clothing $574.71 483 3.3 95 BULK-10eaf370
21556 Bulk Product ae091436 Sports & Outdoors $50.19 490 0.8 6 BULK-3b348682
21557 Bulk Product 1b7fed93 Books $170.93 11 2.5 88 BULK-4678e812
21558 Bulk Product 52dc114b Books $878.60 176 0.8 89 BULK-833e01fd
21559 Bulk Product f1cbec1d Books $687.68 20 0.2 38 BULK-4e9788b6
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