Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

50

Current Page

417 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 417 Results Showing 20801 - 20850 of 24441

ID Name Category Price Stock Rating Reviews SKU
21360 Bulk Product 834935e1 Home & Garden $687.00 337 0.8 57 BULK-dfea1553
21361 Bulk Product a0403240 Home & Garden $204.86 459 3.8 63 BULK-d5e478b5
21362 Bulk Product faa84606 Home & Garden $440.04 260 0.4 70 BULK-09e2f69d
21363 Bulk Product 330d6a00 Electronics $117.60 66 3.2 20 BULK-7a5560c0
21364 Bulk Product 23875741 Toys & Games $628.41 395 3.8 25 BULK-4cd3b345
21365 Bulk Product 19009c2e Electronics $471.00 309 2.4 59 BULK-172bd53f
21366 Bulk Product 67fe6f2d Sports & Outdoors $447.01 128 2.2 52 BULK-9401ac45
21367 Bulk Product 6b3a46a4 Toys & Games $460.19 68 4.0 92 BULK-7e0795f8
21368 Bulk Product acea3bde Toys & Games $65.80 259 2.0 77 BULK-23b17b85
21369 Bulk Product 0182c866 Electronics $957.47 153 0.1 1 BULK-5494b43e
21370 Bulk Product 3aa78a02 Sports & Outdoors $803.14 73 1.4 95 BULK-d9d49f4e
21371 Bulk Product 79127a6d Clothing $633.18 30 2.6 86 BULK-d6e2e3a0
21372 Bulk Product 6532481b Electronics $677.78 369 3.1 38 BULK-9471ed39
21373 Bulk Product aba51b5a Home & Garden $617.54 218 3.8 3 BULK-db30761c
21374 Bulk Product e609bb3e Home & Garden $293.41 278 3.7 26 BULK-7653a791
21375 Bulk Product 534ea730 Toys & Games $952.82 54 3.1 78 BULK-cd9f24eb
21376 Bulk Product c0bb4a4b Books $845.97 2 3.8 68 BULK-f49944fc
21377 Bulk Product f89f1088 Toys & Games $809.42 443 2.7 73 BULK-8b0ec854
21378 Bulk Product 7cc4f8ad Clothing $184.74 131 4.5 87 BULK-b649b2a8
21379 Bulk Product 0c727942 Clothing $335.72 133 4.6 89 BULK-9f3c256e
21380 Bulk Product d1b9a6f7 Toys & Games $827.13 469 3.9 22 BULK-3aeab10f
21381 Bulk Product 0ed7c9bf Electronics $32.65 433 2.2 27 BULK-0c0d9792
21382 Bulk Product 6e1c9753 Sports & Outdoors $130.00 248 4.4 56 BULK-e6468a8a
21383 Bulk Product 9f37a5ad Electronics $817.09 138 3.9 30 BULK-79579c11
21384 Bulk Product 1f6f8080 Sports & Outdoors $441.59 325 3.8 7 BULK-bac5a3a2
21385 Bulk Product 5ccd14ea Toys & Games $157.25 203 0.5 38 BULK-6bcbc517
21386 Bulk Product cc8e7463 Electronics $83.99 284 1.1 54 BULK-aa1a208d
21387 Bulk Product 3261dbc2 Sports & Outdoors $119.29 265 0.7 18 BULK-698723a0
21388 Bulk Product 94d0dd85 Sports & Outdoors $965.38 37 2.4 98 BULK-d1b48a6d
21389 Bulk Product 0e1a957b Toys & Games $470.17 465 3.9 14 BULK-0abdb15a
21390 Bulk Product 0033482b Toys & Games $655.11 132 0.8 15 BULK-8d6bd75c
21391 Bulk Product 2a107804 Home & Garden $387.64 414 4.8 31 BULK-8338dcc0
21392 Bulk Product b7b6154a Books $933.39 69 1.7 71 BULK-138c2622
21393 Bulk Product 93a34d29 Books $915.73 84 0.6 83 BULK-63c056b5
21394 Bulk Product daa0d4fb Home & Garden $941.24 191 4.1 12 BULK-9451d21d
21395 Bulk Product ac004302 Sports & Outdoors $964.40 105 3.4 61 BULK-41e85119
21396 Bulk Product 1358ef11 Sports & Outdoors $718.07 8 1.8 18 BULK-a9161d79
21397 Bulk Product b022d7fb Books $326.63 488 4.0 0 BULK-4fb327b2
21398 Bulk Product 6cd02b55 Sports & Outdoors $64.02 119 2.2 45 BULK-209b9d54
21399 Bulk Product 3cffbdc5 Home & Garden $896.40 265 3.4 20 BULK-dee61fb4
21400 Bulk Product 18371cdd Home & Garden $72.77 223 2.1 95 BULK-3e6aae73
21401 Bulk Product 7379ce22 Clothing $462.91 43 0.2 6 BULK-e184c54a
21402 Bulk Product 21266e90 Toys & Games $430.56 69 0.5 80 BULK-9b621686
21403 Bulk Product 41051bdc Electronics $77.01 41 4.9 41 BULK-d6012d89
21404 Bulk Product 29c73424 Electronics $66.20 206 0.7 78 BULK-7fad0d1b
21405 Bulk Product 40fccbc2 Electronics $92.55 67 2.3 36 BULK-0b900e9d
21406 Bulk Product bc3df27c Clothing $89.60 345 0.0 6 BULK-fcc3abb1
21407 Bulk Product 7a1685f7 Clothing $399.58 487 0.7 8 BULK-91c1d2d6
21408 Bulk Product b544e7bf Home & Garden $111.78 213 2.3 97 BULK-935aa240
21409 Bulk Product f66cc804 Toys & Games $971.06 211 0.2 62 BULK-42e075dc
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