Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 13660 | Bulk Product 411799b9 | Clothing | $554.17 | 433 | ★ 4.6 | 60 | BULK-4992f4a6 |
| 13661 | Bulk Product 31c8e4cd | Sports & Outdoors | $178.25 | 355 | ★ 1.7 | 40 | BULK-9f910804 |
| 13662 | Bulk Product e5e76686 | Books | $532.40 | 212 | ★ 3.5 | 54 | BULK-e0e75412 |
| 13663 | Bulk Product 368154d5 | Home & Garden | $384.10 | 76 | ★ 3.8 | 99 | BULK-a6d36c7b |
| 13664 | Bulk Product 2a9a0d25 | Electronics | $324.99 | 422 | ★ 2.1 | 72 | BULK-3f71304c |
| 13665 | Bulk Product 921788a8 | Books | $862.82 | 140 | ★ 3.6 | 33 | BULK-40de3ecb |
| 13666 | Bulk Product 3d666bdd | Sports & Outdoors | $258.82 | 300 | ★ 5.0 | 64 | BULK-3ae8cbef |
| 13667 | Bulk Product 5d24d2fe | Books | $896.41 | 240 | ★ 4.5 | 3 | BULK-c7ea0cdb |
| 13668 | Bulk Product caa21d69 | Books | $341.99 | 398 | ★ 0.9 | 70 | BULK-4dd7d29a |
| 13669 | Bulk Product 22439ef5 | Books | $152.20 | 156 | ★ 3.1 | 89 | BULK-d55b6ea8 |
| 13670 | Bulk Product c98cc5dc | Sports & Outdoors | $92.36 | 280 | ★ 1.0 | 55 | BULK-4f9ccd8c |
| 13671 | Bulk Product 65e79418 | Toys & Games | $175.34 | 291 | ★ 4.5 | 47 | BULK-920dbbec |
| 13672 | Bulk Product 2f7a2e3d | Clothing | $514.43 | 113 | ★ 2.6 | 16 | BULK-44206da4 |
| 13673 | Bulk Product 71561678 | Books | $827.66 | 268 | ★ 2.9 | 14 | BULK-546479e2 |
| 13674 | Bulk Product 7edc3ff9 | Books | $982.98 | 227 | ★ 0.5 | 79 | BULK-b4da5e11 |
| 13675 | Bulk Product 598ebf15 | Books | $303.68 | 387 | ★ 4.5 | 20 | BULK-bb693eff |
| 13676 | Bulk Product 85dc37b3 | Home & Garden | $622.77 | 208 | ★ 0.5 | 75 | BULK-c5c5c31b |
| 13677 | Bulk Product 7773c104 | Home & Garden | $36.04 | 298 | ★ 3.2 | 14 | BULK-6c0ef46a |
| 13678 | Bulk Product 662495a6 | Toys & Games | $213.50 | 191 | ★ 3.3 | 5 | BULK-b816ddb9 |
| 13679 | Bulk Product b9c44632 | Electronics | $388.90 | 182 | ★ 1.6 | 87 | BULK-4e6f8547 |
| 13680 | Bulk Product e21a64a9 | Clothing | $893.83 | 102 | ★ 1.8 | 37 | BULK-706dcbe4 |
| 13681 | Bulk Product 064611ad | Electronics | $572.80 | 99 | ★ 1.4 | 16 | BULK-783c3c27 |
| 13682 | Bulk Product e5923c3b | Clothing | $796.74 | 249 | ★ 2.7 | 74 | BULK-9e11a4dd |
| 13683 | Bulk Product 179a2168 | Home & Garden | $959.81 | 371 | ★ 1.6 | 99 | BULK-6d454914 |
| 13684 | Bulk Product 3e4f87cd | Clothing | $549.10 | 69 | ★ 3.9 | 53 | BULK-a4bbb9d5 |
| 13685 | Bulk Product 3afa5b7b | Books | $841.58 | 50 | ★ 2.2 | 56 | BULK-b767c118 |
| 13686 | Bulk Product 51a7e7ba | Clothing | $296.73 | 20 | ★ 4.4 | 51 | BULK-60f14db0 |
| 13687 | Bulk Product e372d8ca | Electronics | $81.51 | 157 | ★ 1.6 | 13 | BULK-67f5cf81 |
| 13688 | Bulk Product b29661f2 | Sports & Outdoors | $245.54 | 314 | ★ 3.7 | 76 | BULK-bca03a4c |
| 13689 | Bulk Product 960f50af | Toys & Games | $715.35 | 420 | ★ 1.0 | 94 | BULK-e3984235 |
| 13690 | Bulk Product 7e7c1f89 | Toys & Games | $406.61 | 127 | ★ 3.9 | 35 | BULK-e73e9b7d |
| 13691 | Bulk Product 88e6d0c0 | Clothing | $381.06 | 279 | ★ 0.1 | 34 | BULK-8a15a858 |
| 13692 | Bulk Product 41551984 | Sports & Outdoors | $998.33 | 294 | ★ 2.8 | 42 | BULK-67cb577a |
| 13693 | Bulk Product d1ab90b4 | Electronics | $308.45 | 462 | ★ 0.2 | 43 | BULK-feedb5cd |
| 13694 | Bulk Product 168b1dab | Toys & Games | $634.51 | 495 | ★ 3.8 | 15 | BULK-0c9f08a2 |
| 13695 | Bulk Product c801c111 | Home & Garden | $236.47 | 173 | ★ 3.3 | 14 | BULK-1df956a7 |
| 13696 | Bulk Product 26e5c8eb | Home & Garden | $539.52 | 77 | ★ 2.4 | 38 | BULK-dee66df9 |
| 13697 | Bulk Product 3eeec884 | Sports & Outdoors | $322.25 | 169 | ★ 1.8 | 55 | BULK-2531a1d5 |
| 13698 | Bulk Product aa32cc69 | Sports & Outdoors | $70.44 | 409 | ★ 2.7 | 69 | BULK-bd8a4c80 |
| 13699 | Bulk Product 616d10cd | Electronics | $762.02 | 315 | ★ 3.5 | 12 | BULK-91f5e80e |
| 13700 | Bulk Product f4bade9d | Toys & Games | $673.97 | 162 | ★ 0.7 | 68 | BULK-bc6bf403 |
| 13701 | Bulk Product 229654f2 | Clothing | $481.93 | 269 | ★ 4.2 | 81 | BULK-12c99596 |
| 13702 | Bulk Product 649c68e9 | Clothing | $327.74 | 211 | ★ 2.3 | 54 | BULK-418e39ca |
| 13703 | Bulk Product f7de3b62 | Home & Garden | $34.91 | 116 | ★ 3.2 | 22 | BULK-1151e503 |
| 13704 | Bulk Product 7a36ad47 | Books | $560.24 | 131 | ★ 4.1 | 30 | BULK-a1a90bcb |
| 13705 | Bulk Product acd629f5 | Toys & Games | $127.04 | 275 | ★ 2.0 | 55 | BULK-dd652a76 |
| 13706 | Bulk Product 61bd8660 | Toys & Games | $131.98 | 463 | ★ 2.0 | 68 | BULK-947ba547 |
| 13707 | Bulk Product 5d880ce9 | Sports & Outdoors | $654.23 | 31 | ★ 1.9 | 8 | BULK-3d60f3c9 |
| 13708 | Bulk Product 5f0070d9 | Electronics | $403.87 | 301 | ★ 3.8 | 26 | BULK-fcde786e |
| 13709 | Bulk Product 41f843b5 | Clothing | $372.83 | 170 | ★ 1.3 | 25 | BULK-403c2c24 |
// 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
};
}