Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 24110 | Bulk Product c4437b33 | Books | $452.34 | 459 | ★ 4.0 | 76 | BULK-a0651ce4 |
| 24111 | Bulk Product 5fd02f65 | Clothing | $226.05 | 250 | ★ 3.9 | 97 | BULK-8f16bdb0 |
| 24112 | Bulk Product 23b01236 | Home & Garden | $284.34 | 279 | ★ 4.5 | 18 | BULK-c15b0053 |
| 24113 | Bulk Product dee28abb | Electronics | $60.14 | 350 | ★ 0.8 | 22 | BULK-5a4a02d4 |
| 24114 | Bulk Product 43670b2e | Toys & Games | $410.04 | 204 | ★ 3.5 | 41 | BULK-ad3e756c |
| 24115 | Bulk Product 741c2d83 | Books | $948.92 | 28 | ★ 0.5 | 0 | BULK-8e4543fe |
| 24116 | Bulk Product 8340b493 | Electronics | $635.56 | 23 | ★ 1.0 | 29 | BULK-802e01af |
| 24117 | Bulk Product 3b282c46 | Sports & Outdoors | $651.41 | 376 | ★ 4.1 | 69 | BULK-6dc9be25 |
| 24118 | Bulk Product 833afde8 | Toys & Games | $724.26 | 251 | ★ 3.8 | 12 | BULK-116c0f98 |
| 24119 | Bulk Product de056a2a | Sports & Outdoors | $479.44 | 433 | ★ 4.4 | 46 | BULK-b8bf1768 |
| 24120 | Bulk Product 89febfd3 | Clothing | $756.99 | 244 | ★ 2.7 | 82 | BULK-b46f76b1 |
| 24121 | Bulk Product 054aecc3 | Books | $745.54 | 85 | ★ 0.5 | 6 | BULK-295022b5 |
| 24122 | Bulk Product f4ae389f | Books | $284.87 | 495 | ★ 4.6 | 5 | BULK-c0280bfc |
| 24123 | Bulk Product 21a0ccf5 | Electronics | $431.86 | 23 | ★ 2.6 | 32 | BULK-3099db23 |
| 24124 | Bulk Product abd5ed03 | Toys & Games | $384.13 | 133 | ★ 0.4 | 87 | BULK-d2398417 |
| 24125 | Bulk Product c9437389 | Toys & Games | $674.90 | 351 | ★ 4.4 | 46 | BULK-709b825b |
| 24126 | Bulk Product 3173d292 | Home & Garden | $600.82 | 191 | ★ 3.8 | 85 | BULK-6cae01bf |
| 24127 | Bulk Product 2080d06c | Sports & Outdoors | $547.17 | 303 | ★ 0.7 | 8 | BULK-1477924d |
| 24128 | Bulk Product 281a49f0 | Toys & Games | $522.04 | 174 | ★ 1.3 | 79 | BULK-175a6376 |
| 24129 | Bulk Product d71c4a9f | Clothing | $102.39 | 424 | ★ 2.4 | 92 | BULK-c4237eb1 |
| 24130 | Bulk Product 30924a66 | Clothing | $335.08 | 396 | ★ 4.2 | 58 | BULK-a6b4ffb7 |
| 24131 | Bulk Product c3f814c1 | Clothing | $935.86 | 277 | ★ 2.1 | 0 | BULK-ea4001ae |
| 24132 | Bulk Product d7fa3c55 | Sports & Outdoors | $160.56 | 15 | ★ 0.5 | 61 | BULK-46815570 |
| 24133 | Bulk Product e39f6b03 | Toys & Games | $87.51 | 391 | ★ 4.5 | 36 | BULK-571be625 |
| 24134 | Bulk Product bab8218a | Electronics | $860.81 | 223 | ★ 2.8 | 43 | BULK-5de95f2b |
// 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
};
}