Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 10460 | Bulk Product ab030da6 | Books | $815.62 | 462 | ★ 3.8 | 40 | BULK-ccc90dfa |
| 10461 | Bulk Product 54d0252f | Home & Garden | $818.70 | 14 | ★ 0.3 | 2 | BULK-bda66ad3 |
| 10462 | Bulk Product 42fd88a2 | Electronics | $848.47 | 9 | ★ 3.1 | 20 | BULK-cc2b4656 |
| 10463 | Bulk Product 61e95231 | Electronics | $508.01 | 375 | ★ 0.9 | 88 | BULK-b7341805 |
| 10464 | Bulk Product 71c82a2a | Toys & Games | $243.33 | 256 | ★ 2.0 | 40 | BULK-aaff1171 |
| 10465 | Bulk Product 9f9b4743 | Sports & Outdoors | $157.65 | 403 | ★ 4.9 | 72 | BULK-8fa95cb2 |
| 10466 | Bulk Product bab00a33 | Home & Garden | $971.28 | 433 | ★ 4.8 | 78 | BULK-a44d1173 |
| 10467 | Bulk Product 184f92c6 | Home & Garden | $145.81 | 458 | ★ 3.3 | 42 | BULK-78a5bef4 |
| 10468 | Bulk Product 99809238 | Books | $436.25 | 212 | ★ 1.7 | 61 | BULK-79fb691d |
| 10469 | Bulk Product d03a9e4f | Clothing | $814.27 | 492 | ★ 4.0 | 14 | BULK-64b686a8 |
| 10470 | Bulk Product af82f611 | Toys & Games | $551.31 | 457 | ★ 3.2 | 50 | BULK-e62f1954 |
| 10471 | Bulk Product 78ebd7dc | Books | $356.30 | 129 | ★ 1.3 | 44 | BULK-58ddac8a |
| 10472 | Bulk Product 6b092c50 | Books | $203.66 | 239 | ★ 2.2 | 10 | BULK-552fafeb |
| 10473 | Bulk Product 908d0431 | Books | $205.77 | 119 | ★ 3.8 | 87 | BULK-a10484e2 |
| 10474 | Bulk Product 7d0fd76a | Sports & Outdoors | $905.00 | 379 | ★ 2.8 | 29 | BULK-b94cae1e |
| 10475 | Bulk Product 96c41ae7 | Sports & Outdoors | $370.21 | 483 | ★ 4.2 | 17 | BULK-c0d0d493 |
| 10476 | Bulk Product c01a05cd | Electronics | $356.28 | 351 | ★ 2.9 | 71 | BULK-ca553f07 |
| 10477 | Bulk Product f17180fe | Toys & Games | $77.38 | 401 | ★ 2.3 | 67 | BULK-4e59930e |
| 10478 | Bulk Product 2e6dd608 | Clothing | $279.73 | 33 | ★ 4.3 | 15 | BULK-71803da6 |
| 10479 | Bulk Product c5362caf | Books | $19.23 | 100 | ★ 3.4 | 50 | BULK-afd2fe60 |
| 10480 | Bulk Product 8f3d507a | Clothing | $583.77 | 180 | ★ 3.9 | 79 | BULK-973ce432 |
| 10481 | Bulk Product bc7e66b0 | Sports & Outdoors | $611.50 | 267 | ★ 3.5 | 29 | BULK-c031907d |
| 10482 | Bulk Product 0598d35d | Toys & Games | $883.91 | 52 | ★ 2.2 | 21 | BULK-e0aefd50 |
| 10483 | Bulk Product 97ea7d07 | Electronics | $557.90 | 1 | ★ 4.9 | 59 | BULK-25080311 |
| 10484 | Bulk Product 417e4f90 | Sports & Outdoors | $272.04 | 141 | ★ 0.2 | 24 | BULK-4a612f4c |
// 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
};
}