Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 16010 | Bulk Product f04181c0 | Toys & Games | $289.79 | 244 | ★ 3.9 | 97 | BULK-f11fa396 |
| 16011 | Bulk Product 18ef9749 | Sports & Outdoors | $677.21 | 256 | ★ 1.0 | 61 | BULK-b102c25e |
| 16012 | Bulk Product 8995772a | Clothing | $634.97 | 118 | ★ 2.4 | 45 | BULK-0654b35a |
| 16013 | Bulk Product b98fe0de | Sports & Outdoors | $815.67 | 472 | ★ 4.5 | 66 | BULK-f5e63bc2 |
| 16014 | Bulk Product 9d98c6b8 | Books | $639.72 | 370 | ★ 2.9 | 13 | BULK-77e00617 |
| 16015 | Bulk Product 5abcd128 | Electronics | $925.75 | 315 | ★ 0.8 | 99 | BULK-59d08f8a |
| 16016 | Bulk Product 0c04f336 | Sports & Outdoors | $649.92 | 160 | ★ 4.1 | 62 | BULK-fe861d34 |
| 16017 | Bulk Product abd430cc | Home & Garden | $243.49 | 107 | ★ 1.5 | 90 | BULK-84ce2b1b |
| 16018 | Bulk Product 8720f2b0 | Clothing | $148.58 | 319 | ★ 3.0 | 6 | BULK-b9202fd0 |
| 16019 | Bulk Product f9438948 | Sports & Outdoors | $464.38 | 455 | ★ 3.9 | 51 | BULK-5442d32a |
| 16020 | Bulk Product 7a730605 | Clothing | $410.54 | 68 | ★ 2.8 | 77 | BULK-e9571a54 |
| 16021 | Bulk Product 0c6bdeee | Clothing | $941.92 | 466 | ★ 2.0 | 57 | BULK-60964e56 |
| 16022 | Bulk Product 97641871 | Sports & Outdoors | $943.48 | 257 | ★ 4.7 | 7 | BULK-fcaacc9e |
| 16023 | Bulk Product 83e6cda0 | Clothing | $94.24 | 146 | ★ 2.5 | 14 | BULK-ecc80aad |
| 16024 | Bulk Product ce533114 | Clothing | $209.25 | 453 | ★ 2.0 | 65 | BULK-25e57402 |
| 16025 | Bulk Product 24bf71fd | Home & Garden | $67.42 | 371 | ★ 0.4 | 99 | BULK-f8d8aad6 |
| 16026 | Bulk Product 9eece08e | Electronics | $80.50 | 329 | ★ 4.8 | 80 | BULK-0057674f |
| 16027 | Bulk Product e32908d5 | Sports & Outdoors | $733.60 | 292 | ★ 4.8 | 43 | BULK-61bb8a7e |
| 16028 | Bulk Product ece0605e | Clothing | $330.16 | 425 | ★ 0.7 | 72 | BULK-6489ee36 |
| 16029 | Bulk Product b6bb0355 | Books | $67.29 | 325 | ★ 1.7 | 45 | BULK-6ba955a1 |
| 16030 | Bulk Product d645accd | Home & Garden | $941.79 | 444 | ★ 4.2 | 98 | BULK-18729e47 |
| 16031 | Bulk Product 21e0b2e6 | Toys & Games | $860.24 | 165 | ★ 3.3 | 89 | BULK-bdc00e5b |
| 16032 | Bulk Product 72fd19fb | Electronics | $932.05 | 340 | ★ 2.3 | 92 | BULK-80396fdf |
| 16033 | Bulk Product f2a59a1b | Toys & Games | $358.55 | 281 | ★ 2.3 | 16 | BULK-a16bfef9 |
| 16034 | Bulk Product f61b1b87 | Home & Garden | $673.54 | 466 | ★ 0.6 | 51 | BULK-0da31481 |
| 16035 | Bulk Product e8d67ee7 | Home & Garden | $303.92 | 493 | ★ 4.8 | 44 | BULK-b4dacfda |
| 16036 | Bulk Product 352e3c38 | Sports & Outdoors | $500.43 | 453 | ★ 3.8 | 45 | BULK-40ab399a |
| 16037 | Bulk Product cdc25627 | Sports & Outdoors | $285.08 | 227 | ★ 0.9 | 94 | BULK-08d25385 |
| 16038 | Bulk Product 9cfc2675 | Home & Garden | $143.31 | 32 | ★ 4.0 | 74 | BULK-90f16936 |
| 16039 | Bulk Product 64f33110 | Toys & Games | $333.00 | 183 | ★ 2.9 | 52 | BULK-a4fd4acb |
| 16040 | Bulk Product 5ef29d69 | Toys & Games | $99.47 | 223 | ★ 1.3 | 47 | BULK-8e45daeb |
| 16041 | Bulk Product 05f585e1 | Books | $66.29 | 188 | ★ 1.4 | 21 | BULK-d1c05b4d |
| 16042 | Bulk Product bc197673 | Sports & Outdoors | $56.71 | 7 | ★ 0.6 | 81 | BULK-6ac403f5 |
| 16043 | Bulk Product 3f995883 | Toys & Games | $295.79 | 273 | ★ 3.1 | 62 | BULK-ac0ee8e4 |
| 16044 | Bulk Product da68a099 | Clothing | $923.92 | 197 | ★ 1.5 | 41 | BULK-7ead32c3 |
| 16045 | Bulk Product 00163515 | Toys & Games | $771.22 | 221 | ★ 0.0 | 60 | BULK-21c25746 |
| 16046 | Bulk Product d57c7b76 | Clothing | $55.04 | 433 | ★ 2.0 | 58 | BULK-ed6fa05f |
| 16047 | Bulk Product ffcb093a | Electronics | $535.01 | 400 | ★ 0.6 | 62 | BULK-d5ca0803 |
| 16048 | Bulk Product 0d24d6dc | Home & Garden | $975.98 | 361 | ★ 4.6 | 4 | BULK-5f6593bc |
| 16049 | Bulk Product 2dd21011 | Electronics | $901.28 | 434 | ★ 2.1 | 2 | BULK-86a0d71b |
| 16050 | Bulk Product e74add35 | Books | $55.83 | 27 | ★ 2.1 | 90 | BULK-6d53473f |
| 16051 | Bulk Product 95438ddc | Home & Garden | $12.36 | 357 | ★ 2.7 | 25 | BULK-338fa9ad |
| 16052 | Bulk Product 9d9dd3a7 | Clothing | $404.75 | 293 | ★ 3.2 | 1 | BULK-b1c400d7 |
| 16053 | Bulk Product a95a4e71 | Clothing | $37.12 | 325 | ★ 4.0 | 69 | BULK-be8b3c7e |
| 16054 | Bulk Product c173f02f | Sports & Outdoors | $720.64 | 308 | ★ 3.7 | 1 | BULK-eec2f218 |
| 16055 | Bulk Product f4c1fea8 | Electronics | $782.43 | 334 | ★ 4.9 | 65 | BULK-82a89174 |
| 16056 | Bulk Product 844617c6 | Sports & Outdoors | $767.98 | 34 | ★ 4.1 | 63 | BULK-4a277bca |
| 16057 | Bulk Product 2feaf087 | Sports & Outdoors | $629.32 | 162 | ★ 4.4 | 31 | BULK-cc3afd64 |
| 16058 | Bulk Product 1eddbbf3 | Books | $224.85 | 472 | ★ 3.3 | 53 | BULK-284f87f8 |
| 16059 | Bulk Product ed26945c | Toys & Games | $1,004.69 | 16 | ★ 0.5 | 94 | BULK-8a397350 |
// 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
};
}