Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 24460 | Bulk Product c3dbbb1f | Sports & Outdoors | $943.20 | 197 | ★ 1.0 | 14 | BULK-268a958a |
| 24461 | Bulk Product 2d0ef1bf | Electronics | $206.01 | 212 | ★ 3.8 | 27 | BULK-34e0d90e |
| 24462 | Bulk Product 56ab238c | Books | $992.84 | 303 | ★ 2.1 | 99 | BULK-cff49178 |
| 24463 | Bulk Product 1c4060e6 | Home & Garden | $992.20 | 322 | ★ 1.6 | 99 | BULK-ad95dd06 |
| 24464 | Bulk Product 8632f365 | Books | $758.93 | 170 | ★ 0.3 | 88 | BULK-9a014881 |
| 24465 | Bulk Product fe7744b8 | Clothing | $52.93 | 268 | ★ 1.7 | 71 | BULK-230a30e4 |
| 24466 | Bulk Product 76942f7c | Toys & Games | $852.61 | 448 | ★ 1.5 | 46 | BULK-2af2ef9b |
| 24467 | Bulk Product ef8407a4 | Electronics | $17.42 | 112 | ★ 3.7 | 96 | BULK-f3a9d0ca |
| 24468 | Bulk Product 18434811 | Toys & Games | $454.57 | 328 | ★ 0.5 | 55 | BULK-344af26f |
| 24469 | Bulk Product 50100b3e | Home & Garden | $231.61 | 150 | ★ 2.1 | 69 | BULK-23cdd534 |
| 24470 | Bulk Product 772c3cda | Clothing | $675.48 | 12 | ★ 4.5 | 96 | BULK-c1414186 |
| 24471 | Bulk Product 98df3260 | Toys & Games | $84.71 | 94 | ★ 4.6 | 60 | BULK-d0af81b5 |
| 24472 | Bulk Product bd63e579 | Electronics | $816.82 | 428 | ★ 4.5 | 97 | BULK-6072c16a |
| 24473 | Bulk Product d162feef | Toys & Games | $795.13 | 302 | ★ 1.8 | 12 | BULK-b578dfc4 |
| 24474 | Bulk Product c911b8b4 | Sports & Outdoors | $780.88 | 83 | ★ 2.5 | 6 | BULK-69f5d7c0 |
| 24475 | Bulk Product 5691f62d | Electronics | $425.00 | 295 | ★ 4.5 | 19 | BULK-8dd8b629 |
| 24476 | Bulk Product 892c6cad | Sports & Outdoors | $184.65 | 111 | ★ 1.8 | 15 | BULK-0646b5f5 |
| 24477 | Bulk Product 085e9ed2 | Sports & Outdoors | $307.41 | 85 | ★ 4.0 | 42 | BULK-51057da5 |
| 24478 | Bulk Product 76dd25cd | Clothing | $951.28 | 103 | ★ 2.0 | 67 | BULK-89217ef0 |
| 24479 | Bulk Product bd46ca9a | Home & Garden | $154.69 | 227 | ★ 2.7 | 19 | BULK-11ed595a |
| 24480 | Bulk Product ea4f1a16 | Sports & Outdoors | $771.78 | 387 | ★ 0.4 | 34 | BULK-ee27eaae |
| 24481 | Bulk Product faf7622a | Books | $833.58 | 330 | ★ 3.0 | 81 | BULK-3edf15b7 |
| 24482 | Bulk Product 3b265f65 | Books | $358.81 | 122 | ★ 0.7 | 13 | BULK-8f2f98c2 |
| 24483 | Bulk Product ea502e4f | Home & Garden | $472.64 | 425 | ★ 0.3 | 97 | BULK-5b48c030 |
| 24484 | Bulk Product 80a41118 | Electronics | $670.12 | 305 | ★ 3.0 | 38 | BULK-5711fa44 |
// 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
};
}