Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 18260 | Bulk Product 2594b2db | Electronics | $821.76 | 241 | ★ 1.0 | 75 | BULK-0fc55b4c |
| 18261 | Bulk Product 97344815 | Home & Garden | $534.81 | 208 | ★ 4.9 | 66 | BULK-1e380e62 |
| 18262 | Bulk Product 3c741ca5 | Books | $678.89 | 348 | ★ 3.5 | 69 | BULK-8c1b5e6e |
| 18263 | Bulk Product 2bdd334b | Toys & Games | $151.53 | 375 | ★ 4.1 | 77 | BULK-bb2a2869 |
| 18264 | Bulk Product ce5d5503 | Sports & Outdoors | $535.92 | 107 | ★ 2.0 | 11 | BULK-a758f70c |
| 18265 | Bulk Product 7099e731 | Electronics | $213.56 | 402 | ★ 4.0 | 21 | BULK-aa0cb176 |
| 18266 | Bulk Product dc51a180 | Clothing | $20.47 | 134 | ★ 4.0 | 5 | BULK-36d37eb9 |
| 18267 | Bulk Product 07d02512 | Electronics | $381.47 | 112 | ★ 1.6 | 95 | BULK-a4525ca2 |
| 18268 | Bulk Product 50242fde | Electronics | $880.73 | 376 | ★ 0.8 | 34 | BULK-d864a488 |
| 18269 | Bulk Product 2bf7243c | Toys & Games | $301.14 | 141 | ★ 3.7 | 60 | BULK-4390ee34 |
| 18270 | Bulk Product a79b5855 | Sports & Outdoors | $463.41 | 79 | ★ 4.4 | 35 | BULK-bdede83a |
| 18271 | Bulk Product 9d96a7dc | Electronics | $260.23 | 293 | ★ 4.6 | 12 | BULK-4bec14a8 |
| 18272 | Bulk Product 0c6b41e7 | Clothing | $396.18 | 3 | ★ 1.0 | 15 | BULK-9a072a80 |
| 18273 | Bulk Product e85756dd | Toys & Games | $71.21 | 416 | ★ 4.6 | 54 | BULK-c1876261 |
| 18274 | Bulk Product d675d46b | Toys & Games | $973.62 | 359 | ★ 0.1 | 31 | BULK-448fddd5 |
| 18275 | Bulk Product c5ba8c01 | Sports & Outdoors | $1,000.31 | 453 | ★ 1.7 | 24 | BULK-e4cd185b |
| 18276 | Bulk Product 6abca393 | Sports & Outdoors | $760.35 | 9 | ★ 2.3 | 93 | BULK-aedc566f |
| 18277 | Bulk Product ed0f8707 | Sports & Outdoors | $608.30 | 56 | ★ 3.0 | 27 | BULK-07fc3307 |
| 18278 | Bulk Product 00dc3b5a | Books | $407.07 | 245 | ★ 0.1 | 56 | BULK-edb813d2 |
| 18279 | Bulk Product a192cf02 | Clothing | $38.00 | 357 | ★ 3.5 | 12 | BULK-44e2d0ae |
| 18280 | Bulk Product b89e12b8 | Sports & Outdoors | $883.37 | 116 | ★ 3.0 | 28 | BULK-ea088b18 |
| 18281 | Bulk Product 3f27e813 | Toys & Games | $357.98 | 188 | ★ 0.2 | 9 | BULK-170c415e |
| 18282 | Bulk Product 16477f22 | Electronics | $615.09 | 285 | ★ 0.1 | 50 | BULK-8fa40648 |
| 18283 | Bulk Product 4422ca90 | Clothing | $513.67 | 406 | ★ 3.0 | 95 | BULK-c6b81ab4 |
| 18284 | Bulk Product faf0511d | Home & Garden | $789.19 | 379 | ★ 1.9 | 70 | BULK-93f45906 |
// 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
};
}