Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 7435 | Bulk Product ca79ff88 | Books | $623.44 | 44 | ★ 2.6 | 37 | BULK-3de65f94 |
| 7436 | Bulk Product 2c674e0c | Clothing | $603.97 | 67 | ★ 4.2 | 86 | BULK-74c3ffb2 |
| 7437 | Bulk Product 4a8b1eab | Books | $304.72 | 181 | ★ 2.8 | 34 | BULK-51d87dfc |
| 7438 | Bulk Product 50395b30 | Clothing | $185.86 | 74 | ★ 2.0 | 9 | BULK-6697d578 |
| 7439 | Bulk Product eed34066 | Books | $262.97 | 176 | ★ 3.2 | 67 | BULK-86a10679 |
| 7440 | Bulk Product a450018b | Clothing | $980.78 | 465 | ★ 1.6 | 70 | BULK-bbd12093 |
| 7441 | Bulk Product 726fbfd6 | Sports & Outdoors | $87.74 | 250 | ★ 4.2 | 41 | BULK-11482033 |
| 7442 | Bulk Product 69b98569 | Home & Garden | $398.81 | 102 | ★ 1.7 | 17 | BULK-866bd267 |
| 7443 | Bulk Product cfd96963 | Electronics | $190.47 | 205 | ★ 3.9 | 42 | BULK-f757261f |
| 7444 | Bulk Product 2822591a | Home & Garden | $642.96 | 363 | ★ 3.3 | 23 | BULK-8989b2a3 |
| 7445 | Bulk Product 5a991746 | Home & Garden | $436.73 | 409 | ★ 2.9 | 69 | BULK-eef0e28d |
| 7446 | Bulk Product dc29d4bc | Books | $812.36 | 126 | ★ 1.8 | 85 | BULK-8fea9baf |
| 7447 | Bulk Product 47e04d39 | Books | $670.74 | 450 | ★ 2.9 | 39 | BULK-c256de57 |
| 7448 | Bulk Product d5cf5c52 | Books | $153.57 | 176 | ★ 4.5 | 23 | BULK-8f4805a5 |
| 7449 | Bulk Product d9412afa | Clothing | $169.60 | 267 | ★ 2.7 | 81 | BULK-3ea9b8f3 |
| 7450 | Bulk Product beef2e22 | Clothing | $78.65 | 140 | ★ 0.2 | 96 | BULK-a26da253 |
| 7451 | Bulk Product 6f088d36 | Clothing | $71.62 | 140 | ★ 4.8 | 9 | BULK-d3733c4a |
| 7452 | Bulk Product c35dc320 | Books | $893.80 | 450 | ★ 4.0 | 14 | BULK-284c95b8 |
| 7453 | Bulk Product e655676d | Clothing | $888.73 | 353 | ★ 4.6 | 5 | BULK-a9dbb127 |
| 7454 | Bulk Product cd37c24e | Home & Garden | $68.04 | 271 | ★ 0.6 | 6 | BULK-d416453b |
| 7455 | Bulk Product 6b759f1b | Home & Garden | $122.52 | 202 | ★ 0.2 | 34 | BULK-6f651399 |
| 7456 | Bulk Product df7ae649 | Clothing | $397.94 | 239 | ★ 3.3 | 56 | BULK-269ac0c5 |
| 7457 | Bulk Product 2c8aeab0 | Toys & Games | $21.05 | 101 | ★ 1.8 | 11 | BULK-9264a11d |
| 7458 | Bulk Product ea31ec64 | Electronics | $627.69 | 376 | ★ 1.7 | 38 | BULK-187e882f |
| 7459 | Bulk Product 26813ca1 | Home & Garden | $945.31 | 492 | ★ 2.5 | 58 | BULK-a6251080 |
// 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
};
}