Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 10460 | Bulk Product ab030da6 | Books | $815.62 | 462 | ★ 3.8 | 40 | BULK-ccc90dfa |
| 10461 | Bulk Product 54d0252f | Home & Garden | $818.70 | 14 | ★ 0.3 | 2 | BULK-bda66ad3 |
| 10462 | Bulk Product 42fd88a2 | Electronics | $848.47 | 9 | ★ 3.1 | 20 | BULK-cc2b4656 |
| 10463 | Bulk Product 61e95231 | Electronics | $508.01 | 375 | ★ 0.9 | 88 | BULK-b7341805 |
| 10464 | Bulk Product 71c82a2a | Toys & Games | $243.33 | 256 | ★ 2.0 | 40 | BULK-aaff1171 |
| 10465 | Bulk Product 9f9b4743 | Sports & Outdoors | $157.65 | 403 | ★ 4.9 | 72 | BULK-8fa95cb2 |
| 10466 | Bulk Product bab00a33 | Home & Garden | $971.28 | 433 | ★ 4.8 | 78 | BULK-a44d1173 |
| 10467 | Bulk Product 184f92c6 | Home & Garden | $145.81 | 458 | ★ 3.3 | 42 | BULK-78a5bef4 |
| 10468 | Bulk Product 99809238 | Books | $436.25 | 212 | ★ 1.7 | 61 | BULK-79fb691d |
| 10469 | Bulk Product d03a9e4f | Clothing | $814.27 | 492 | ★ 4.0 | 14 | BULK-64b686a8 |
| 10470 | Bulk Product af82f611 | Toys & Games | $551.31 | 457 | ★ 3.2 | 50 | BULK-e62f1954 |
| 10471 | Bulk Product 78ebd7dc | Books | $356.30 | 129 | ★ 1.3 | 44 | BULK-58ddac8a |
| 10472 | Bulk Product 6b092c50 | Books | $203.66 | 239 | ★ 2.2 | 10 | BULK-552fafeb |
| 10473 | Bulk Product 908d0431 | Books | $205.77 | 119 | ★ 3.8 | 87 | BULK-a10484e2 |
| 10474 | Bulk Product 7d0fd76a | Sports & Outdoors | $905.00 | 379 | ★ 2.8 | 29 | BULK-b94cae1e |
| 10475 | Bulk Product 96c41ae7 | Sports & Outdoors | $370.21 | 483 | ★ 4.2 | 17 | BULK-c0d0d493 |
| 10476 | Bulk Product c01a05cd | Electronics | $356.28 | 351 | ★ 2.9 | 71 | BULK-ca553f07 |
| 10477 | Bulk Product f17180fe | Toys & Games | $77.38 | 401 | ★ 2.3 | 67 | BULK-4e59930e |
| 10478 | Bulk Product 2e6dd608 | Clothing | $279.73 | 33 | ★ 4.3 | 15 | BULK-71803da6 |
| 10479 | Bulk Product c5362caf | Books | $19.23 | 100 | ★ 3.4 | 50 | BULK-afd2fe60 |
| 10480 | Bulk Product 8f3d507a | Clothing | $583.77 | 180 | ★ 3.9 | 79 | BULK-973ce432 |
| 10481 | Bulk Product bc7e66b0 | Sports & Outdoors | $611.50 | 267 | ★ 3.5 | 29 | BULK-c031907d |
| 10482 | Bulk Product 0598d35d | Toys & Games | $883.91 | 52 | ★ 2.2 | 21 | BULK-e0aefd50 |
| 10483 | Bulk Product 97ea7d07 | Electronics | $557.90 | 1 | ★ 4.9 | 59 | BULK-25080311 |
| 10484 | Bulk Product 417e4f90 | Sports & Outdoors | $272.04 | 141 | ★ 0.2 | 24 | BULK-4a612f4c |
| 10485 | Bulk Product dab1e557 | Sports & Outdoors | $928.15 | 94 | ★ 0.4 | 58 | BULK-506f22d3 |
| 10486 | Bulk Product d6766ed8 | Sports & Outdoors | $985.24 | 463 | ★ 3.1 | 54 | BULK-83e0d44f |
| 10487 | Bulk Product c7e46cb3 | Home & Garden | $337.20 | 464 | ★ 1.8 | 70 | BULK-05d2227d |
| 10488 | Bulk Product 56601995 | Electronics | $179.90 | 246 | ★ 1.4 | 57 | BULK-f39a8994 |
| 10489 | Bulk Product 5224dac4 | Sports & Outdoors | $821.32 | 8 | ★ 1.2 | 6 | BULK-ff39ddfb |
| 10490 | Bulk Product 7ab71023 | Sports & Outdoors | $150.52 | 489 | ★ 0.7 | 93 | BULK-8c44e4df |
| 10491 | Bulk Product eb3e15ce | Books | $602.71 | 451 | ★ 0.1 | 48 | BULK-200e8c08 |
| 10492 | Bulk Product 63e72787 | Clothing | $52.57 | 48 | ★ 2.3 | 84 | BULK-5e355fde |
| 10493 | Bulk Product 9b483eca | Sports & Outdoors | $323.55 | 489 | ★ 1.7 | 83 | BULK-61ecc65f |
| 10494 | Bulk Product ff8634e7 | Clothing | $656.45 | 203 | ★ 3.3 | 97 | BULK-1d69d899 |
| 10495 | Bulk Product a989e3fa | Home & Garden | $607.61 | 72 | ★ 1.8 | 80 | BULK-fa7d517e |
| 10496 | Bulk Product a7fccd13 | Home & Garden | $890.65 | 67 | ★ 3.0 | 37 | BULK-acbe9d68 |
| 10497 | Bulk Product 001de619 | Sports & Outdoors | $633.88 | 199 | ★ 3.4 | 47 | BULK-a68c8f5a |
| 10498 | Bulk Product 74690e03 | Clothing | $783.23 | 41 | ★ 3.5 | 22 | BULK-d95031ed |
| 10499 | Bulk Product dc95a9fe | Sports & Outdoors | $791.39 | 486 | ★ 0.6 | 46 | BULK-b0ccf033 |
| 10500 | Bulk Product b5149614 | Electronics | $31.51 | 327 | ★ 2.7 | 75 | BULK-b7e9a233 |
| 10501 | Bulk Product 700e7f6c | Home & Garden | $1,006.74 | 98 | ★ 1.0 | 80 | BULK-a4a7e9ba |
| 10502 | Bulk Product 614b6750 | Toys & Games | $876.30 | 439 | ★ 1.0 | 13 | BULK-ec6dd410 |
| 10503 | Bulk Product c8523278 | Home & Garden | $812.47 | 373 | ★ 4.2 | 97 | BULK-f86d1723 |
| 10504 | Bulk Product 13f00113 | Clothing | $856.57 | 445 | ★ 1.5 | 50 | BULK-0ddbde1a |
| 10505 | Bulk Product 2f967b7a | Sports & Outdoors | $533.68 | 336 | ★ 1.6 | 14 | BULK-801b9313 |
| 10506 | Bulk Product 0cb9acb4 | Home & Garden | $597.07 | 135 | ★ 2.3 | 64 | BULK-f4459557 |
| 10507 | Bulk Product 9c8a71f1 | Toys & Games | $695.17 | 409 | ★ 3.9 | 22 | BULK-76255acd |
| 10508 | Bulk Product 507205f0 | Electronics | $919.58 | 18 | ★ 3.6 | 94 | BULK-b47f5152 |
| 10509 | Bulk Product f706c08b | Toys & Games | $843.98 | 306 | ★ 4.1 | 59 | BULK-9ac09d70 |
// 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
};
}