Efficient Pagination with Skip/Take

Efficient pagination using OFFSET-FETCH on SQL Server.

Execution Time

21 ms

Page Size

50

Current Page

239 / 489

Total Records

24441

Items per page: 25 50 100 200

Page 239 Results Showing 11901 - 11950 of 24441

ID Name Category Price Stock Rating Reviews SKU
12460 Bulk Product ac819610 Electronics $664.76 133 2.8 71 BULK-4af1de86
12461 Bulk Product da4c81a9 Clothing $406.08 385 4.7 81 BULK-9c078c3b
12462 Bulk Product 173db9cd Home & Garden $230.07 107 3.0 60 BULK-5c7ff23e
12463 Bulk Product c2fc34f3 Clothing $139.45 186 2.2 91 BULK-7b67963b
12464 Bulk Product a342a029 Books $172.23 103 1.3 1 BULK-262ef2cb
12465 Bulk Product c015806a Clothing $558.01 445 3.3 92 BULK-041e81ac
12466 Bulk Product 79da9ce4 Clothing $802.67 271 3.9 39 BULK-5a4fa728
12467 Bulk Product b528b944 Clothing $539.98 254 2.5 3 BULK-371db358
12468 Bulk Product 498ff0c1 Clothing $615.88 25 0.6 44 BULK-ac8ab8f4
12469 Bulk Product 696c14ae Sports & Outdoors $861.00 302 2.2 8 BULK-f8ca40b7
12470 Bulk Product afc87bb8 Sports & Outdoors $593.16 350 2.4 67 BULK-c66100a0
12471 Bulk Product 651f5c88 Clothing $243.29 354 2.9 44 BULK-fd5932d7
12472 Bulk Product d42a530e Sports & Outdoors $869.50 197 3.1 9 BULK-3ad52581
12473 Bulk Product 59d28d64 Electronics $519.70 159 2.1 59 BULK-766daea4
12474 Bulk Product aca45491 Toys & Games $555.86 136 1.9 63 BULK-7a6ecaeb
12475 Bulk Product 9fecec55 Clothing $215.37 151 2.4 97 BULK-a54658ed
12476 Bulk Product 6cddb3e0 Clothing $419.94 305 2.9 58 BULK-116c63da
12477 Bulk Product d0baa85b Toys & Games $155.53 225 1.3 25 BULK-dedeb10e
12478 Bulk Product 46e186b6 Clothing $908.07 463 2.9 65 BULK-d2e7aac8
12479 Bulk Product c08ac4d5 Clothing $366.23 74 4.6 41 BULK-f0e2c438
12480 Bulk Product ebfebb70 Home & Garden $481.28 383 3.8 1 BULK-e882d4ba
12481 Bulk Product c42784ea Home & Garden $713.70 493 2.5 91 BULK-93e97432
12482 Bulk Product ecfaa8a6 Toys & Games $866.67 364 0.6 67 BULK-84929863
12483 Bulk Product 9e9477c5 Books $550.01 330 3.6 79 BULK-9dbef7cd
12484 Bulk Product 40d03ea4 Sports & Outdoors $267.78 297 3.0 60 BULK-a4a18592
12485 Bulk Product 1d412436 Books $862.26 135 3.7 47 BULK-f7de7505
12486 Bulk Product 0dc178f0 Sports & Outdoors $729.49 59 3.7 36 BULK-9d2ca56e
12487 Bulk Product afaec45c Home & Garden $449.03 20 1.1 65 BULK-87dbd68a
12488 Bulk Product 267b0405 Books $917.82 184 2.2 50 BULK-d243bea9
12489 Bulk Product 6b2edc01 Home & Garden $133.05 468 2.1 74 BULK-949e61f5
12490 Bulk Product c4af50b9 Books $422.94 57 1.0 89 BULK-c06073c9
12491 Bulk Product cb24fefc Sports & Outdoors $783.77 235 0.8 49 BULK-c26d5376
12492 Bulk Product d8d57f9d Home & Garden $973.77 479 2.7 55 BULK-081a8e0a
12493 Bulk Product 0487a1aa Toys & Games $902.07 16 2.2 80 BULK-e46c97c8
12494 Bulk Product 0409a501 Toys & Games $145.44 298 1.5 96 BULK-8b8d4e59
12495 Bulk Product 1bf9d778 Electronics $321.53 387 0.6 25 BULK-fc32cc5b
12496 Bulk Product 21641f4a Books $968.02 479 1.5 29 BULK-1e8b974c
12497 Bulk Product b544292e Sports & Outdoors $323.72 141 2.2 64 BULK-51ed2bf1
12498 Bulk Product 5fb1c682 Books $877.39 129 4.2 74 BULK-b61b395e
12499 Bulk Product b125d979 Home & Garden $598.27 475 3.2 35 BULK-d8170321
12500 Bulk Product 293fecdb Clothing $281.72 298 0.7 42 BULK-7c4d7663
12501 Bulk Product 8ed31d9f Clothing $204.78 474 3.6 62 BULK-a327761e
12502 Bulk Product 020e1680 Clothing $944.18 332 2.1 46 BULK-76ba1cd1
12503 Bulk Product 18c9ad2e Toys & Games $811.85 18 3.4 54 BULK-82fef43f
12504 Bulk Product ae9949e0 Electronics $180.50 1 0.1 21 BULK-dbed6248
12505 Bulk Product a232d3d0 Home & Garden $252.30 133 2.6 57 BULK-8557ea96
12506 Bulk Product 30bf7dcf Clothing $554.44 75 3.8 16 BULK-b5726487
12507 Bulk Product 48a09d91 Home & Garden $903.54 85 4.6 47 BULK-18093a72
12508 Bulk Product 3d0be94d Home & Garden $761.84 352 1.5 94 BULK-5a5262dd
12509 Bulk Product c8a63e95 Toys & Games $423.68 139 4.1 22 BULK-0114f0aa
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