Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

79 ms

Page Size

50

Current Page

436 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 436 Results Showing 21751 - 21800 of 24441

ID Name Category Price Stock Rating Reviews SKU
22310 Bulk Product 9afb9aa5 Home & Garden $996.73 405 0.7 36 BULK-6995922f
22311 Bulk Product 3d5cfe89 Home & Garden $719.96 83 2.2 99 BULK-a51c45d5
22312 Bulk Product f446b3d9 Sports & Outdoors $176.68 499 4.5 18 BULK-9c8666c0
22313 Bulk Product d1251dc1 Sports & Outdoors $1,000.18 91 1.4 65 BULK-6d279b88
22314 Bulk Product b50e481e Electronics $455.23 441 0.0 31 BULK-021fd020
22315 Bulk Product 320412be Electronics $917.57 483 4.5 3 BULK-1abc9974
22316 Bulk Product ef182e18 Clothing $624.43 26 4.4 88 BULK-ea71dbe2
22317 Bulk Product 0c95d16f Electronics $734.85 367 0.7 94 BULK-f50a10be
22318 Bulk Product bc13a890 Sports & Outdoors $889.18 303 3.1 63 BULK-0e70fb47
22319 Bulk Product e0cd7e0a Home & Garden $637.23 62 1.9 50 BULK-bc581004
22320 Bulk Product 50691ef7 Sports & Outdoors $350.46 232 3.0 21 BULK-57d3fbf8
22321 Bulk Product be1b7c7b Electronics $949.44 329 0.4 2 BULK-0157b137
22322 Bulk Product 867599a4 Clothing $816.46 102 1.5 50 BULK-cc6dd69a
22323 Bulk Product d82a6f68 Electronics $197.28 316 0.6 60 BULK-35affc6f
22324 Bulk Product f1b9511d Home & Garden $27.79 133 0.7 37 BULK-7d4fe4cd
22325 Bulk Product 48d6637b Sports & Outdoors $194.68 179 4.1 16 BULK-505ffbe0
22326 Bulk Product c3b669c6 Electronics $473.88 63 4.8 51 BULK-398b255f
22327 Bulk Product 922b132d Clothing $610.76 27 4.4 40 BULK-e57fdc6d
22328 Bulk Product cd9d1d12 Home & Garden $108.74 11 2.6 52 BULK-96d06c13
22329 Bulk Product 4bfbc1a8 Home & Garden $769.33 346 2.0 75 BULK-d5477870
22330 Bulk Product c975b4ea Sports & Outdoors $264.86 253 1.4 93 BULK-649898fb
22331 Bulk Product e98d3284 Home & Garden $906.03 353 3.8 49 BULK-34e33b61
22332 Bulk Product 881d00fa Clothing $810.32 204 2.2 2 BULK-ff0003d9
22333 Bulk Product 7c83a61b Clothing $711.06 293 2.1 53 BULK-d4fbf965
22334 Bulk Product ef718b48 Books $939.13 343 1.9 44 BULK-fdd68efa
22335 Bulk Product 0c56a982 Home & Garden $856.76 371 1.4 82 BULK-e5d5d301
22336 Bulk Product 04d6696d Home & Garden $840.64 385 3.7 30 BULK-8937cf77
22337 Bulk Product 36725086 Clothing $143.65 348 3.7 41 BULK-6e3527db
22338 Bulk Product 40353650 Clothing $683.02 279 0.4 9 BULK-12115a74
22339 Bulk Product 45179bb7 Electronics $415.82 413 1.5 26 BULK-a74ebb3d
22340 Bulk Product 70847c09 Sports & Outdoors $22.33 220 1.2 44 BULK-a7892117
22341 Bulk Product 659a39b9 Clothing $807.44 492 0.2 30 BULK-7cc85898
22342 Bulk Product 105ea1a1 Toys & Games $951.84 479 3.6 57 BULK-0f86f28e
22343 Bulk Product ef7fb07a Home & Garden $735.18 178 4.3 7 BULK-1669f69b
22344 Bulk Product c69b4e76 Electronics $66.15 359 2.0 23 BULK-b757daf4
22345 Bulk Product 2d67b106 Clothing $435.06 433 1.2 37 BULK-334019d1
22346 Bulk Product 29e6d47f Clothing $366.15 12 0.7 9 BULK-b8d8d3be
22347 Bulk Product ffd76d0d Sports & Outdoors $655.85 221 4.8 71 BULK-e5dc17d5
22348 Bulk Product a982f52c Books $784.20 292 1.0 59 BULK-11a75a83
22349 Bulk Product c0ecc2c3 Sports & Outdoors $624.09 103 0.6 86 BULK-8a0c2f27
22350 Bulk Product e5cf82c6 Electronics $943.92 140 2.7 87 BULK-1020990f
22351 Bulk Product b087a1fa Sports & Outdoors $613.25 380 0.3 35 BULK-9687438b
22352 Bulk Product d72038f1 Home & Garden $696.81 422 0.7 61 BULK-38cb2770
22353 Bulk Product 32d02123 Books $146.49 71 0.7 88 BULK-555cdca5
22354 Bulk Product 6e4b1465 Clothing $497.63 14 1.1 3 BULK-7f4a5154
22355 Bulk Product 227b8ce6 Home & Garden $665.11 261 2.9 62 BULK-1f664490
22356 Bulk Product 97cb80b4 Home & Garden $631.31 458 4.1 33 BULK-ed4eb02c
22357 Bulk Product 9ef662d9 Sports & Outdoors $940.09 239 2.7 29 BULK-e7254716
22358 Bulk Product 8ddb0b89 Sports & Outdoors $479.02 165 3.3 51 BULK-134ba6ce
22359 Bulk Product c541a497 Toys & Games $909.90 184 4.6 19 BULK-9fec8d14
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