Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

18 ms

Page Size

50

Current Page

200 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 200 Results Showing 9951 - 10000 of 24441

ID Name Category Price Stock Rating Reviews SKU
10510 Bulk Product 5c5a487a Clothing $827.27 231 1.2 92 BULK-27274de4
10511 Bulk Product d893e944 Home & Garden $263.79 16 0.1 84 BULK-3de7dc39
10512 Bulk Product 18e796dc Clothing $891.69 155 1.7 91 BULK-968d672e
10513 Bulk Product 0dbf98c2 Sports & Outdoors $630.85 497 2.2 86 BULK-009b5555
10514 Bulk Product 1fedde86 Sports & Outdoors $664.08 181 1.6 53 BULK-2d12de69
10515 Bulk Product 59498582 Books $136.87 181 2.3 80 BULK-43c36bfc
10516 Bulk Product 3514e04b Sports & Outdoors $443.57 237 4.2 27 BULK-61439f87
10517 Bulk Product c1d28a1a Toys & Games $460.13 51 2.4 71 BULK-b90a7ed3
10518 Bulk Product 997d3383 Electronics $809.93 297 4.0 18 BULK-73ed8f20
10519 Bulk Product c41d2e75 Clothing $751.37 127 3.0 33 BULK-86dd7209
10520 Bulk Product d9d59f30 Books $381.01 160 0.6 63 BULK-466cc520
10521 Bulk Product 70d0085e Toys & Games $887.96 15 0.4 48 BULK-6856c290
10522 Bulk Product a5c71f58 Toys & Games $193.89 226 3.4 48 BULK-48e02fe0
10523 Bulk Product faa8ee94 Toys & Games $209.48 413 3.0 93 BULK-9593775f
10524 Bulk Product 9131f6d2 Toys & Games $578.10 88 4.1 59 BULK-5be07fe4
10525 Bulk Product 25f58f14 Electronics $540.16 106 1.8 79 BULK-88496ae0
10526 Bulk Product 0f9300c8 Toys & Games $447.21 133 3.7 95 BULK-01817abf
10527 Bulk Product 4c03d18b Books $734.98 111 2.2 48 BULK-c18f9acd
10528 Bulk Product 94c32420 Sports & Outdoors $347.04 46 4.1 63 BULK-daee1820
10529 Bulk Product d185fa24 Sports & Outdoors $457.67 292 1.7 76 BULK-9a669126
10530 Bulk Product 59539d4d Books $207.91 204 3.8 41 BULK-213369b2
10531 Bulk Product 8ecbad6d Electronics $48.05 55 3.2 28 BULK-d9ab1ab4
10532 Bulk Product b54f9c69 Clothing $494.22 473 1.9 54 BULK-56e8da9f
10533 Bulk Product 2b8f9818 Clothing $381.27 3 1.4 44 BULK-ebd776e2
10534 Bulk Product 838e2095 Clothing $358.76 160 2.6 32 BULK-c773f183
10535 Bulk Product 43a32ec5 Home & Garden $755.89 49 1.6 83 BULK-bdc98050
10536 Bulk Product 4c0ed2ea Books $812.77 93 2.9 86 BULK-30575a1b
10537 Bulk Product b186cedf Electronics $212.32 102 0.7 0 BULK-a9d621e1
10538 Bulk Product b9e8f393 Books $351.65 3 3.1 76 BULK-b640c368
10539 Bulk Product 0c7e4d48 Clothing $947.00 447 1.3 32 BULK-5472518d
10540 Bulk Product 19986bf4 Clothing $33.59 368 2.5 24 BULK-3ef88a15
10541 Bulk Product acd4239b Toys & Games $302.35 141 3.1 98 BULK-ca81a78c
10542 Bulk Product 552cff6b Electronics $871.96 243 4.7 32 BULK-1025d133
10543 Bulk Product 2e7678e6 Clothing $646.73 412 2.0 89 BULK-a5f2778a
10544 Bulk Product bbf0ce58 Electronics $383.60 172 4.5 38 BULK-1559f40f
10545 Bulk Product ebb56482 Books $221.61 394 4.6 3 BULK-5ab2c503
10546 Bulk Product dbd1ecee Home & Garden $156.87 407 4.4 72 BULK-c2853ee4
10547 Bulk Product b8d7dc98 Books $58.87 485 2.6 72 BULK-421f0245
10548 Bulk Product 55849927 Clothing $269.22 236 4.2 58 BULK-529fff32
10549 Bulk Product 38364dc4 Toys & Games $440.44 485 2.2 67 BULK-8d028ba1
10550 Bulk Product 19366457 Books $847.00 185 3.8 69 BULK-7192baa9
10551 Bulk Product 6b1e2a66 Toys & Games $898.88 56 2.1 8 BULK-77c5bb9c
10552 Bulk Product 68954f27 Home & Garden $570.30 251 0.8 95 BULK-bef4288b
10553 Bulk Product b43f9e1b Home & Garden $333.03 381 0.2 26 BULK-41659ff6
10554 Bulk Product c48cdb9b Clothing $920.58 98 1.2 1 BULK-ffcffeec
10555 Bulk Product 849a2016 Toys & Games $251.16 369 1.1 18 BULK-1784fb6d
10556 Bulk Product a3e80170 Home & Garden $911.34 229 0.1 0 BULK-43c79f97
10557 Bulk Product a7c15f13 Sports & Outdoors $151.59 479 0.2 8 BULK-3165d12f
10558 Bulk Product 0da12b06 Toys & Games $639.11 85 1.1 82 BULK-dc7cda01
10559 Bulk Product 797d23a6 Clothing $183.43 235 3.7 53 BULK-228e77df
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