Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

47 ms

Page Size

50

Current Page

161 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 161 Results Showing 8001 - 8050 of 24441

ID Name Category Price Stock Rating Reviews SKU
8560 Bulk Product 4b89cf73 Clothing $391.20 175 2.3 25 BULK-1bec8fcb
8561 Bulk Product bd5b7cf2 Toys & Games $303.25 40 2.5 59 BULK-0507aadf
8562 Bulk Product 268167e4 Clothing $538.68 10 2.8 35 BULK-32989ecb
8563 Bulk Product 31c73b01 Electronics $416.16 16 2.6 10 BULK-50395944
8564 Bulk Product 34b3288b Sports & Outdoors $516.52 28 4.1 73 BULK-13b20f2b
8565 Bulk Product e8b84591 Clothing $319.82 69 2.2 4 BULK-66d70b4f
8566 Bulk Product e556d796 Toys & Games $695.74 350 0.9 28 BULK-5f1f8e67
8567 Bulk Product 631a8b61 Home & Garden $219.64 467 3.6 6 BULK-bea1e8eb
8568 Bulk Product 723e9eb7 Electronics $253.48 231 2.9 74 BULK-509c55c8
8569 Bulk Product 549b8039 Home & Garden $110.46 224 0.5 20 BULK-141aaf96
8570 Bulk Product ed0d6975 Books $867.98 322 0.6 8 BULK-6c97c4a9
8571 Bulk Product de3e5302 Books $550.81 37 4.6 69 BULK-682b855d
8572 Bulk Product a69464c4 Sports & Outdoors $400.81 268 1.5 97 BULK-afa8e7b1
8573 Bulk Product 29e72787 Books $924.32 59 1.3 85 BULK-2ff47ba7
8574 Bulk Product 4274e6c6 Electronics $855.87 198 0.7 12 BULK-a87c336e
8575 Bulk Product ba6c8f19 Toys & Games $860.05 198 3.7 9 BULK-d7d31679
8576 Bulk Product e95d222c Home & Garden $130.39 265 0.2 29 BULK-736a8dc6
8577 Bulk Product e23ffdca Sports & Outdoors $241.48 114 3.4 34 BULK-f58a0cc0
8578 Bulk Product 2243e866 Sports & Outdoors $107.65 113 2.8 14 BULK-7878052b
8579 Bulk Product 0d1c349b Electronics $614.67 371 1.7 13 BULK-000f734a
8580 Bulk Product 40c7d45f Toys & Games $937.29 151 1.4 48 BULK-452fa1bd
8581 Bulk Product 368ac37b Clothing $710.43 308 3.0 41 BULK-d401ee0c
8582 Bulk Product fa2dcde9 Clothing $256.35 387 4.0 99 BULK-4023cd85
8583 Bulk Product 2730a55a Home & Garden $215.14 221 2.1 93 BULK-6fbddea8
8584 Bulk Product cf46103c Clothing $277.91 87 1.6 78 BULK-8a072cfa
8585 Bulk Product 8ae982a0 Sports & Outdoors $213.27 198 0.4 26 BULK-9caf3a84
8586 Bulk Product 1f5ec184 Toys & Games $643.55 412 4.6 47 BULK-e65735a0
8587 Bulk Product a9613279 Clothing $116.16 444 1.2 89 BULK-2af61c40
8588 Bulk Product ad579172 Books $917.05 256 3.3 87 BULK-158c2ca0
8589 Bulk Product eb41be88 Books $195.25 319 4.1 90 BULK-a717f4cf
8590 Bulk Product ae642e32 Books $50.28 441 0.8 43 BULK-76e2c575
8591 Bulk Product 6ed6274a Clothing $788.45 139 1.1 24 BULK-2896918f
8592 Bulk Product a4de2db3 Clothing $625.53 379 1.3 94 BULK-25bd5695
8593 Bulk Product c844e09e Toys & Games $370.08 399 1.2 84 BULK-1eb0b27b
8594 Bulk Product 12d906f4 Books $959.88 47 0.5 4 BULK-636a1721
8595 Bulk Product 18bc3cff Electronics $768.36 279 0.6 8 BULK-d4ab4745
8596 Bulk Product 7f46bae3 Sports & Outdoors $463.34 247 3.8 82 BULK-98d2d9af
8597 Bulk Product 8e297c09 Home & Garden $756.39 118 0.8 50 BULK-9fee1090
8598 Bulk Product cfc5a997 Toys & Games $968.87 327 3.8 33 BULK-3fe0c260
8599 Bulk Product 9cf9acdb Home & Garden $365.04 209 0.1 73 BULK-cd5021a9
8600 Bulk Product 0d66d749 Sports & Outdoors $576.88 93 4.4 72 BULK-be0866b7
8601 Bulk Product 50db41d0 Books $635.52 350 2.2 17 BULK-f221580c
8602 Bulk Product 1f765a33 Toys & Games $204.10 470 3.1 84 BULK-e8bd7810
8603 Bulk Product 5c7b0d11 Toys & Games $282.07 179 2.4 89 BULK-6bcd805b
8604 Bulk Product dc2c86dc Home & Garden $750.90 23 4.0 47 BULK-71403456
8605 Bulk Product 43d973b5 Clothing $968.61 417 4.2 63 BULK-699726e7
8606 Bulk Product f2531047 Books $594.93 80 3.2 24 BULK-ce20b706
8607 Bulk Product f19de393 Sports & Outdoors $193.78 183 2.4 87 BULK-b9ee80e5
8608 Bulk Product 526614e4 Books $367.22 337 1.0 4 BULK-a14e7a58
8609 Bulk Product e839486d Home & Garden $970.34 398 1.4 8 BULK-740ba356
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