Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 18385 | Bulk Product 971b98eb | Toys & Games | $655.92 | 55 | ★ 4.3 | 67 | BULK-bd832c99 |
| 18386 | Bulk Product cdafe24e | Home & Garden | $415.78 | 146 | ★ 4.4 | 6 | BULK-320309ea |
| 18387 | Bulk Product 9635dcaa | Clothing | $226.94 | 289 | ★ 0.8 | 72 | BULK-96d35355 |
| 18388 | Bulk Product 50aa1238 | Home & Garden | $561.08 | 83 | ★ 3.0 | 58 | BULK-d9bc7268 |
| 18389 | Bulk Product 07f75070 | Clothing | $531.66 | 207 | ★ 4.1 | 81 | BULK-e064942e |
| 18390 | Bulk Product 0ed08582 | Clothing | $701.09 | 493 | ★ 4.7 | 65 | BULK-b7d2ed91 |
| 18391 | Bulk Product 01fbf8db | Sports & Outdoors | $357.11 | 29 | ★ 3.9 | 33 | BULK-968e919c |
| 18392 | Bulk Product c4a7071f | Books | $921.90 | 66 | ★ 1.6 | 47 | BULK-c96803f1 |
| 18393 | Bulk Product 241809de | Electronics | $450.40 | 117 | ★ 3.8 | 40 | BULK-141d5d38 |
| 18394 | Bulk Product 8df217b1 | Sports & Outdoors | $173.40 | 414 | ★ 1.5 | 58 | BULK-c00fa22e |
| 18395 | Bulk Product 15beec90 | Electronics | $54.83 | 306 | ★ 5.0 | 54 | BULK-bdba87f3 |
| 18396 | Bulk Product 79c326db | Sports & Outdoors | $603.88 | 70 | ★ 1.2 | 94 | BULK-8fcce943 |
| 18397 | Bulk Product 0169b325 | Sports & Outdoors | $285.65 | 497 | ★ 1.2 | 6 | BULK-6a577120 |
| 18398 | Bulk Product c2804175 | Electronics | $272.69 | 480 | ★ 0.7 | 40 | BULK-23b7a9c1 |
| 18399 | Bulk Product e7d33b8b | Toys & Games | $389.31 | 204 | ★ 0.9 | 83 | BULK-ce9e90bd |
| 18400 | Bulk Product 6d8f3820 | Sports & Outdoors | $495.84 | 290 | ★ 3.1 | 48 | BULK-c9fecc53 |
| 18401 | Bulk Product 1714b2c5 | Home & Garden | $842.45 | 8 | ★ 3.8 | 19 | BULK-2bbfda99 |
| 18402 | Bulk Product deebf0a9 | Clothing | $345.61 | 351 | ★ 4.1 | 15 | BULK-b04fab95 |
| 18403 | Bulk Product 8e26ae96 | Clothing | $951.26 | 288 | ★ 2.7 | 82 | BULK-f569a989 |
| 18404 | Bulk Product b36a1b3d | Sports & Outdoors | $124.51 | 170 | ★ 3.5 | 44 | BULK-8d7629a5 |
| 18405 | Bulk Product 48399e2e | Toys & Games | $384.89 | 474 | ★ 0.2 | 75 | BULK-ee1378ce |
| 18406 | Bulk Product 7c4c2f42 | Sports & Outdoors | $885.17 | 148 | ★ 3.6 | 45 | BULK-6b843c17 |
| 18407 | Bulk Product b5bcf634 | Books | $517.64 | 89 | ★ 0.4 | 68 | BULK-709f07d7 |
| 18408 | Bulk Product e79d5e2b | Books | $411.72 | 365 | ★ 3.1 | 27 | BULK-c4047a18 |
| 18409 | Bulk Product 3ae63010 | Books | $310.44 | 350 | ★ 0.9 | 76 | BULK-dd422d77 |
// 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
};
}