Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 24685 | Bulk Product 8393f308 | Toys & Games | $655.21 | 130 | ★ 0.7 | 80 | BULK-d45a6a2f |
| 24686 | Bulk Product 7a6c4184 | Sports & Outdoors | $892.58 | 297 | ★ 4.0 | 13 | BULK-b6586361 |
| 24687 | Bulk Product 06750cca | Toys & Games | $803.08 | 29 | ★ 2.6 | 95 | BULK-c85147ff |
| 24688 | Bulk Product 017f2927 | Toys & Games | $209.47 | 36 | ★ 3.0 | 37 | BULK-7b3d2a66 |
| 24689 | Bulk Product 71e552fb | Clothing | $925.46 | 230 | ★ 2.5 | 68 | BULK-0d6b729a |
| 24690 | Bulk Product 9abe0353 | Books | $472.78 | 175 | ★ 4.3 | 22 | BULK-2bc7ff75 |
| 24691 | Bulk Product e0217152 | Toys & Games | $459.05 | 166 | ★ 0.9 | 44 | BULK-95f33e6c |
| 24692 | Bulk Product 2c15dc0d | Clothing | $522.97 | 438 | ★ 2.2 | 87 | BULK-b0ffa157 |
| 24693 | Bulk Product e7f932ce | Home & Garden | $972.57 | 442 | ★ 1.1 | 37 | BULK-e0975117 |
| 24694 | Bulk Product 31197b89 | Toys & Games | $501.18 | 368 | ★ 3.5 | 39 | BULK-8da9054a |
| 24695 | Bulk Product e75e540c | Sports & Outdoors | $958.67 | 382 | ★ 2.5 | 88 | BULK-396b8977 |
| 24696 | Bulk Product 85dbd4ff | Books | $785.37 | 291 | ★ 0.6 | 94 | BULK-d414d97e |
| 24697 | Bulk Product f87cac6b | Toys & Games | $720.42 | 92 | ★ 2.8 | 11 | BULK-3bdca679 |
| 24698 | Bulk Product 360617d5 | Electronics | $863.55 | 363 | ★ 4.8 | 23 | BULK-bb7a5215 |
| 24699 | Bulk Product 21f234ba | Home & Garden | $641.00 | 118 | ★ 0.0 | 94 | BULK-5447ee30 |
| 24700 | Bulk Product 9704a430 | Toys & Games | $271.21 | 156 | ★ 2.1 | 76 | BULK-1cec3387 |
| 24701 | Bulk Product 7c3ba02a | Home & Garden | $729.36 | 123 | ★ 4.2 | 22 | BULK-722ec8e2 |
| 24702 | Bulk Product ecc18f93 | Home & Garden | $182.50 | 379 | ★ 1.9 | 26 | BULK-7d4b92a5 |
| 24703 | Bulk Product 29d49133 | Sports & Outdoors | $905.66 | 466 | ★ 3.7 | 35 | BULK-29303ee6 |
| 24704 | Bulk Product 4050bc72 | Home & Garden | $450.94 | 428 | ★ 0.4 | 71 | BULK-04c2252a |
| 24705 | Bulk Product 0d5f8e8a | Electronics | $256.41 | 491 | ★ 1.5 | 59 | BULK-33fe4579 |
| 24706 | Bulk Product 7dd5e164 | Toys & Games | $888.43 | 489 | ★ 1.6 | 84 | BULK-25d84a73 |
| 24707 | Bulk Product 88424426 | Clothing | $335.11 | 361 | ★ 2.7 | 14 | BULK-a205ce8b |
| 24708 | Bulk Product f0975f8e | Toys & Games | $819.37 | 486 | ★ 4.5 | 18 | BULK-5f3ba09e |
| 24709 | Bulk Product 2830c762 | Home & Garden | $772.83 | 489 | ★ 1.7 | 60 | BULK-ed856fea |
// 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
};
}