Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 14485 | Bulk Product 460022a5 | Books | $1,007.65 | 139 | ★ 1.9 | 56 | BULK-9cda37be |
| 14486 | Bulk Product 10624770 | Sports & Outdoors | $740.03 | 205 | ★ 2.2 | 69 | BULK-741e9bb3 |
| 14487 | Bulk Product 5774a8ea | Electronics | $722.29 | 371 | ★ 4.7 | 54 | BULK-82695413 |
| 14488 | Bulk Product 783ff43d | Clothing | $809.05 | 28 | ★ 5.0 | 12 | BULK-3c40daab |
| 14489 | Bulk Product 62a88444 | Home & Garden | $278.77 | 255 | ★ 4.6 | 34 | BULK-38e3edbf |
| 14490 | Bulk Product b8979f3c | Books | $581.77 | 219 | ★ 4.5 | 86 | BULK-509d6c4f |
| 14491 | Bulk Product 8bf7ee4d | Sports & Outdoors | $537.93 | 369 | ★ 3.0 | 11 | BULK-309a85cc |
| 14492 | Bulk Product a2808a02 | Sports & Outdoors | $14.17 | 42 | ★ 3.0 | 97 | BULK-824a9155 |
| 14493 | Bulk Product 9f6f4c55 | Clothing | $116.10 | 32 | ★ 2.0 | 49 | BULK-68be543c |
| 14494 | Bulk Product 3132aa38 | Clothing | $65.77 | 498 | ★ 0.8 | 3 | BULK-7a6f0daf |
| 14495 | Bulk Product d56b3ccc | Clothing | $526.56 | 473 | ★ 3.4 | 71 | BULK-cafe491a |
| 14496 | Bulk Product 995a27b4 | Books | $704.54 | 49 | ★ 0.5 | 57 | BULK-d8c6ef91 |
| 14497 | Bulk Product e7435ed7 | Home & Garden | $132.64 | 206 | ★ 1.1 | 20 | BULK-b3973e74 |
| 14498 | Bulk Product 569e46e4 | Sports & Outdoors | $151.29 | 311 | ★ 0.8 | 30 | BULK-7371e0ea |
| 14499 | Bulk Product 25e35880 | Toys & Games | $282.69 | 431 | ★ 3.5 | 47 | BULK-b228c83a |
| 14500 | Bulk Product c50a7b58 | Home & Garden | $215.08 | 143 | ★ 2.2 | 82 | BULK-a9e63dc3 |
| 14501 | Bulk Product bdf6870b | Toys & Games | $232.32 | 370 | ★ 3.3 | 85 | BULK-7b7d2d63 |
| 14502 | Bulk Product 8989e1a6 | Toys & Games | $889.57 | 230 | ★ 1.3 | 39 | BULK-6cb27787 |
| 14503 | Bulk Product e3ff71bd | Toys & Games | $737.80 | 132 | ★ 1.4 | 92 | BULK-cf0c9fc2 |
| 14504 | Bulk Product e7d0b0b3 | Books | $793.47 | 346 | ★ 3.8 | 55 | BULK-6fa1a1c5 |
| 14505 | Bulk Product 6fbfd81b | Electronics | $535.52 | 116 | ★ 3.3 | 54 | BULK-db7a880e |
| 14506 | Bulk Product f8e11838 | Home & Garden | $216.00 | 153 | ★ 0.5 | 71 | BULK-5f5c6b02 |
| 14507 | Bulk Product f75e0f9e | Sports & Outdoors | $864.42 | 136 | ★ 4.5 | 99 | BULK-673afd9b |
| 14508 | Bulk Product 860b710b | Clothing | $298.19 | 108 | ★ 3.2 | 5 | BULK-ff5a5a24 |
| 14509 | Bulk Product 43c364ef | Sports & Outdoors | $661.94 | 277 | ★ 1.1 | 71 | BULK-b5f6b57e |
// 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
};
}