Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8610 | Bulk Product b800aca7 | Toys & Games | $926.37 | 263 | ★ 3.7 | 43 | BULK-472d4f51 |
| 8611 | Bulk Product 6c614784 | Electronics | $326.38 | 105 | ★ 0.2 | 44 | BULK-dd4ebe3e |
| 8612 | Bulk Product a4832d07 | Electronics | $502.18 | 396 | ★ 4.4 | 38 | BULK-4c970a61 |
| 8613 | Bulk Product b4360b78 | Home & Garden | $349.64 | 268 | ★ 3.0 | 68 | BULK-699f7eda |
| 8614 | Bulk Product 34e3d65a | Books | $359.07 | 22 | ★ 1.4 | 28 | BULK-5b419293 |
| 8615 | Bulk Product 398dbd87 | Electronics | $322.68 | 114 | ★ 3.9 | 60 | BULK-3d657c6d |
| 8616 | Bulk Product a354bf5e | Clothing | $545.63 | 433 | ★ 4.1 | 7 | BULK-df7e6518 |
| 8617 | Bulk Product b5e94b51 | Clothing | $148.81 | 119 | ★ 2.7 | 49 | BULK-1187907d |
| 8618 | Bulk Product f62f08cb | Electronics | $274.23 | 305 | ★ 2.5 | 33 | BULK-1f72e87e |
| 8619 | Bulk Product 4db1f23a | Toys & Games | $957.89 | 181 | ★ 1.8 | 28 | BULK-5a3a8f7c |
| 8620 | Bulk Product d0cb0af7 | Toys & Games | $895.57 | 481 | ★ 4.6 | 83 | BULK-7a0a93ac |
| 8621 | Bulk Product ab45ef79 | Sports & Outdoors | $575.47 | 116 | ★ 2.4 | 38 | BULK-1f3f0132 |
| 8622 | Bulk Product 3e8f4b43 | Sports & Outdoors | $973.95 | 277 | ★ 3.1 | 93 | BULK-3c941d88 |
| 8623 | Bulk Product 404a7a2b | Sports & Outdoors | $414.26 | 443 | ★ 3.8 | 26 | BULK-dc2034c9 |
| 8624 | Bulk Product 21df6992 | Clothing | $869.49 | 40 | ★ 1.7 | 81 | BULK-2e4642da |
| 8625 | Bulk Product 9ffeab75 | Clothing | $57.23 | 94 | ★ 2.4 | 31 | BULK-f1073af9 |
| 8626 | Bulk Product 39262c4a | Toys & Games | $206.46 | 311 | ★ 3.0 | 85 | BULK-d5631bf1 |
| 8627 | Bulk Product 22ff9183 | Clothing | $378.57 | 451 | ★ 3.8 | 72 | BULK-8ff9dd2b |
| 8628 | Bulk Product bf80a4a1 | Toys & Games | $632.05 | 53 | ★ 2.2 | 99 | BULK-b46f936a |
| 8629 | Bulk Product 91d8c34c | Home & Garden | $946.85 | 61 | ★ 4.5 | 86 | BULK-870516dd |
| 8630 | Bulk Product c107bbbe | Electronics | $256.54 | 194 | ★ 4.9 | 97 | BULK-8afaf6d8 |
| 8631 | Bulk Product 41d8db00 | Clothing | $442.38 | 359 | ★ 3.5 | 29 | BULK-575168bd |
| 8632 | Bulk Product fb11bec8 | Clothing | $681.78 | 289 | ★ 2.1 | 99 | BULK-6327faaf |
| 8633 | Bulk Product 5c35e854 | Sports & Outdoors | $999.61 | 18 | ★ 0.7 | 65 | BULK-ee0df196 |
| 8634 | Bulk Product 57241e4e | Home & Garden | $513.67 | 479 | ★ 3.7 | 84 | BULK-18414880 |
// 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
};
}