Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

46 ms

Page Size

50

Current Page

334 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 334 Results Showing 16651 - 16700 of 24441

ID Name Category Price Stock Rating Reviews SKU
17210 Bulk Product 14252cad Sports & Outdoors $389.47 234 1.7 35 BULK-5f962950
17211 Bulk Product a1b87c7c Clothing $73.59 339 1.2 20 BULK-cc26e3ea
17212 Bulk Product 831458c7 Books $54.70 498 4.3 73 BULK-9208650b
17213 Bulk Product a7357540 Home & Garden $38.16 384 0.4 16 BULK-05f09b70
17214 Bulk Product 3d6c6b15 Home & Garden $129.26 152 1.3 96 BULK-cf139391
17215 Bulk Product eb196320 Home & Garden $560.57 72 3.2 7 BULK-601082a6
17216 Bulk Product b8f70fbd Sports & Outdoors $276.01 301 1.3 80 BULK-ef51b635
17217 Bulk Product a9cd0dfd Home & Garden $801.70 37 1.6 68 BULK-41a68c44
17218 Bulk Product 2e568ef0 Home & Garden $534.59 19 1.6 8 BULK-5138ce8c
17219 Bulk Product ca459994 Books $282.73 387 4.6 94 BULK-64ccd24c
17220 Bulk Product 9da4452e Electronics $727.73 403 2.5 89 BULK-f708c068
17221 Bulk Product 284e5889 Clothing $188.30 18 4.1 43 BULK-facd5646
17222 Bulk Product 9d775997 Books $23.38 325 4.2 41 BULK-6db23dae
17223 Bulk Product 67debe50 Home & Garden $733.34 5 4.5 29 BULK-4e249189
17224 Bulk Product b266395b Electronics $588.28 319 0.6 7 BULK-b39cc050
17225 Bulk Product fb7e9e30 Home & Garden $854.54 238 3.9 75 BULK-60df432a
17226 Bulk Product f300d140 Books $534.82 382 3.0 77 BULK-4650ef51
17227 Bulk Product e3180ae9 Toys & Games $807.66 111 4.6 86 BULK-7612b5cf
17228 Bulk Product 0c239644 Clothing $106.71 4 4.8 14 BULK-044d061f
17229 Bulk Product 76b7258a Sports & Outdoors $304.05 0 1.3 34 BULK-e73745b1
17230 Bulk Product 0062db01 Toys & Games $771.93 336 3.6 81 BULK-ea5e4e3c
17231 Bulk Product 08a91463 Electronics $812.34 266 2.3 60 BULK-4447b879
17232 Bulk Product 9df7fe17 Home & Garden $756.51 183 2.1 87 BULK-5f4a40e7
17233 Bulk Product 6f92cee2 Toys & Games $182.33 469 4.3 46 BULK-6616a17c
17234 Bulk Product f9aaee99 Home & Garden $12.23 428 3.0 27 BULK-de629e4f
17235 Bulk Product 92ab94ed Books $582.19 167 1.1 39 BULK-f78d0104
17236 Bulk Product 579943ff Clothing $605.70 17 2.3 32 BULK-519fd1e5
17237 Bulk Product f4b18e91 Toys & Games $98.27 301 3.8 24 BULK-16e0360b
17238 Bulk Product efcf03cc Sports & Outdoors $317.46 322 4.0 40 BULK-9b31ca4f
17239 Bulk Product a402c9cd Electronics $539.66 331 0.2 8 BULK-2f459ef9
17240 Bulk Product 67549014 Home & Garden $89.61 388 3.4 95 BULK-c74f97f2
17241 Bulk Product 8505a279 Toys & Games $806.26 160 2.5 48 BULK-a076d266
17242 Bulk Product 31dda3d3 Toys & Games $301.84 496 0.7 95 BULK-33ea2ab5
17243 Bulk Product 2da35bd8 Home & Garden $247.83 144 1.0 8 BULK-38a21f89
17244 Bulk Product 8838cdf1 Sports & Outdoors $675.54 353 4.1 35 BULK-35dd3ef8
17245 Bulk Product 0a7e0d12 Electronics $818.09 11 3.0 58 BULK-806918ff
17246 Bulk Product c722fe1c Clothing $160.92 9 0.8 40 BULK-df76c07c
17247 Bulk Product c03535af Clothing $88.86 443 1.9 73 BULK-6d482900
17248 Bulk Product 2dc6e94a Books $771.24 296 4.4 42 BULK-02c08b06
17249 Bulk Product f3c0e44a Clothing $593.70 260 0.0 42 BULK-2f6f2838
17250 Bulk Product 1d2e3dba Toys & Games $556.19 333 3.2 39 BULK-5b56aec2
17251 Bulk Product 110a0ff9 Electronics $830.51 254 1.5 35 BULK-bc1da8c0
17252 Bulk Product 5739f623 Electronics $686.98 200 2.6 51 BULK-b7185a17
17253 Bulk Product bddbc2f6 Clothing $945.41 361 1.6 34 BULK-c74071c8
17254 Bulk Product 4ec48f68 Electronics $880.50 197 2.4 32 BULK-96d3ec55
17255 Bulk Product 9c31a897 Home & Garden $568.59 390 3.3 61 BULK-6973d8be
17256 Bulk Product 98536d27 Electronics $128.88 263 3.8 60 BULK-b48a4ab3
17257 Bulk Product 1387eacf Electronics $45.98 330 4.5 41 BULK-d23d8b35
17258 Bulk Product 79de1e80 Electronics $263.06 92 2.1 71 BULK-3998d7e8
17259 Bulk Product 093346d7 Sports & Outdoors $671.84 347 4.7 53 BULK-c500cc70
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