Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 10560 | Bulk Product 82349e94 | Home & Garden | $604.97 | 81 | ★ 2.8 | 54 | BULK-620c15f8 |
| 10561 | Bulk Product 6c42173b | Home & Garden | $675.15 | 283 | ★ 2.5 | 1 | BULK-b9f64b26 |
| 10562 | Bulk Product 5971cafc | Home & Garden | $926.15 | 457 | ★ 2.4 | 49 | BULK-a8bfb027 |
| 10563 | Bulk Product faebefa6 | Clothing | $601.33 | 404 | ★ 4.4 | 24 | BULK-55861901 |
| 10564 | Bulk Product 156238f1 | Clothing | $805.14 | 44 | ★ 4.7 | 20 | BULK-21577d46 |
| 10565 | Bulk Product 3f1453d8 | Home & Garden | $496.55 | 87 | ★ 3.9 | 41 | BULK-51bcbfc1 |
| 10566 | Bulk Product 2365a6e9 | Clothing | $385.21 | 58 | ★ 4.2 | 19 | BULK-aef1fd05 |
| 10567 | Bulk Product 1f4c05a0 | Electronics | $562.45 | 129 | ★ 3.3 | 1 | BULK-36b43c7e |
| 10568 | Bulk Product 06aee662 | Sports & Outdoors | $995.06 | 14 | ★ 4.0 | 6 | BULK-126c7a8a |
| 10569 | Bulk Product 601038dd | Toys & Games | $506.95 | 270 | ★ 0.3 | 9 | BULK-6a9c23d5 |
| 10570 | Bulk Product 3cb2fb8a | Clothing | $132.40 | 414 | ★ 0.5 | 39 | BULK-5b9c4a2a |
| 10571 | Bulk Product 3a10f6f4 | Books | $121.16 | 52 | ★ 3.8 | 72 | BULK-b64163a6 |
| 10572 | Bulk Product 77b46bdb | Electronics | $266.28 | 41 | ★ 4.6 | 25 | BULK-47271e63 |
| 10573 | Bulk Product bf3e9e23 | Clothing | $620.18 | 463 | ★ 2.2 | 14 | BULK-6fb82eda |
| 10574 | Bulk Product 83984ebe | Books | $918.99 | 130 | ★ 1.8 | 30 | BULK-368860ba |
| 10575 | Bulk Product 9ecb88d3 | Electronics | $218.62 | 82 | ★ 0.6 | 26 | BULK-a770f06b |
| 10576 | Bulk Product 65c9bf35 | Sports & Outdoors | $772.87 | 413 | ★ 4.9 | 51 | BULK-4d5ebb5e |
| 10577 | Bulk Product 16c0e3d7 | Home & Garden | $629.15 | 310 | ★ 1.4 | 46 | BULK-75a93951 |
| 10578 | Bulk Product a704c214 | Clothing | $842.71 | 220 | ★ 4.7 | 69 | BULK-e6391718 |
| 10579 | Bulk Product ae15cd30 | Books | $229.81 | 405 | ★ 4.0 | 46 | BULK-98208a4c |
| 10580 | Bulk Product da3c2fd1 | Clothing | $854.14 | 388 | ★ 2.1 | 75 | BULK-e28673bd |
| 10581 | Bulk Product 05047122 | Toys & Games | $118.62 | 281 | ★ 1.2 | 88 | BULK-cb5e0cb3 |
| 10582 | Bulk Product 8f80f31b | Toys & Games | $478.25 | 56 | ★ 2.5 | 97 | BULK-7542e074 |
| 10583 | Bulk Product 1cde1cc6 | Home & Garden | $335.51 | 233 | ★ 1.7 | 65 | BULK-c39a32a8 |
| 10584 | Bulk Product cbcf3ebd | Electronics | $315.78 | 212 | ★ 0.6 | 99 | BULK-e4ca11ed |
| 10585 | Bulk Product 91933a8b | Sports & Outdoors | $701.97 | 407 | ★ 4.9 | 38 | BULK-2630e088 |
| 10586 | Bulk Product 39c2fcb1 | Sports & Outdoors | $98.98 | 292 | ★ 2.1 | 30 | BULK-a99bed74 |
| 10587 | Bulk Product d318bdd0 | Books | $966.43 | 26 | ★ 0.7 | 69 | BULK-95b42966 |
| 10588 | Bulk Product 70d64e3a | Home & Garden | $136.40 | 308 | ★ 1.8 | 9 | BULK-1c9ca312 |
| 10589 | Bulk Product 199074f9 | Clothing | $316.87 | 191 | ★ 4.3 | 19 | BULK-965e9573 |
| 10590 | Bulk Product bf54e81d | Sports & Outdoors | $649.99 | 179 | ★ 1.1 | 7 | BULK-ee598631 |
| 10591 | Bulk Product 103ab6f6 | Home & Garden | $367.22 | 209 | ★ 3.8 | 13 | BULK-292f5809 |
| 10592 | Bulk Product dd9ed3dd | Books | $640.84 | 427 | ★ 3.3 | 78 | BULK-0579fa3d |
| 10593 | Bulk Product 8c1cf77f | Clothing | $655.11 | 142 | ★ 0.5 | 52 | BULK-5037c083 |
| 10594 | Bulk Product 81ed9328 | Toys & Games | $446.29 | 447 | ★ 2.3 | 0 | BULK-d73b3d12 |
| 10595 | Bulk Product 2e80ec78 | Sports & Outdoors | $506.54 | 478 | ★ 0.2 | 84 | BULK-e26bbeac |
| 10596 | Bulk Product b5d794bb | Electronics | $433.23 | 374 | ★ 0.5 | 30 | BULK-5cc03fdf |
| 10597 | Bulk Product dda3a411 | Clothing | $232.82 | 422 | ★ 2.1 | 66 | BULK-886355dd |
| 10598 | Bulk Product dc2fc0f3 | Electronics | $418.39 | 233 | ★ 2.9 | 2 | BULK-cf1fd1fe |
| 10599 | Bulk Product bb17b9d8 | Electronics | $760.48 | 28 | ★ 1.4 | 6 | BULK-b6ea2f56 |
| 10600 | Bulk Product 2c392ff6 | Clothing | $439.31 | 293 | ★ 1.5 | 43 | BULK-b86cbb81 |
| 10601 | Bulk Product 31eab6d0 | Sports & Outdoors | $424.74 | 498 | ★ 1.8 | 57 | BULK-ed017d3c |
| 10602 | Bulk Product a1fe5b67 | Toys & Games | $466.89 | 269 | ★ 4.0 | 40 | BULK-e51ea144 |
| 10603 | Bulk Product e16df839 | Books | $325.66 | 434 | ★ 2.4 | 38 | BULK-183f606c |
| 10604 | Bulk Product f81e41ba | Electronics | $525.18 | 338 | ★ 3.5 | 91 | BULK-98425180 |
| 10605 | Bulk Product e9f1695a | Sports & Outdoors | $655.12 | 413 | ★ 0.2 | 85 | BULK-51f1f80a |
| 10606 | Bulk Product 28958d4c | Sports & Outdoors | $93.40 | 159 | ★ 2.2 | 99 | BULK-f43c67ab |
| 10607 | Bulk Product cdc40404 | Books | $829.10 | 199 | ★ 1.5 | 61 | BULK-9ae3ac81 |
| 10608 | Bulk Product 83437562 | Sports & Outdoors | $450.95 | 65 | ★ 0.3 | 25 | BULK-a35afcc1 |
| 10609 | Bulk Product 36e1b325 | Clothing | $766.76 | 244 | ★ 4.2 | 67 | BULK-f4127e45 |
// 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
};
}