Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 7710 | Bulk Product e2aa77fd | Books | $68.09 | 160 | ★ 4.2 | 63 | BULK-65d79f67 |
| 7711 | Bulk Product b13d049d | Home & Garden | $732.83 | 32 | ★ 2.3 | 99 | BULK-7181b912 |
| 7712 | Bulk Product a1fece7b | Books | $707.70 | 363 | ★ 4.9 | 67 | BULK-da4abc98 |
| 7713 | Bulk Product da65eae5 | Sports & Outdoors | $377.09 | 450 | ★ 2.4 | 60 | BULK-67d1069c |
| 7714 | Bulk Product d8b6481f | Electronics | $143.76 | 425 | ★ 5.0 | 29 | BULK-ee460bbe |
| 7715 | Bulk Product da8b06bc | Clothing | $478.60 | 448 | ★ 1.2 | 67 | BULK-6c5e9dd1 |
| 7716 | Bulk Product e4112db3 | Books | $212.56 | 342 | ★ 4.2 | 56 | BULK-ccff6a49 |
| 7717 | Bulk Product c4c88064 | Electronics | $232.00 | 387 | ★ 2.5 | 56 | BULK-e0384725 |
| 7718 | Bulk Product 0c4b46a3 | Books | $67.89 | 315 | ★ 2.5 | 44 | BULK-d11faade |
| 7719 | Bulk Product 5b902bd8 | Sports & Outdoors | $988.84 | 344 | ★ 0.6 | 25 | BULK-e98e5cf7 |
| 7720 | Bulk Product 9aa4cbf0 | Sports & Outdoors | $243.77 | 154 | ★ 1.6 | 29 | BULK-b118b77a |
| 7721 | Bulk Product 119ff1de | Sports & Outdoors | $543.92 | 75 | ★ 4.3 | 35 | BULK-ea940cc4 |
| 7722 | Bulk Product ae775bf6 | Books | $388.21 | 298 | ★ 1.8 | 55 | BULK-f994ee0c |
| 7723 | Bulk Product 3f1667c6 | Electronics | $674.74 | 175 | ★ 4.7 | 21 | BULK-189655eb |
| 7724 | Bulk Product 29846b3a | Clothing | $792.01 | 9 | ★ 1.5 | 44 | BULK-0ff15adf |
| 7725 | Bulk Product 3c3bfbbc | Clothing | $19.73 | 230 | ★ 4.4 | 10 | BULK-76a6b284 |
| 7726 | Bulk Product b123b68f | Home & Garden | $443.04 | 177 | ★ 0.1 | 77 | BULK-72a7be00 |
| 7727 | Bulk Product 3c0fc181 | Books | $342.87 | 59 | ★ 3.7 | 47 | BULK-4650d4c4 |
| 7728 | Bulk Product 14cb084c | Toys & Games | $191.28 | 22 | ★ 1.7 | 37 | BULK-8356ea9e |
| 7729 | Bulk Product 98e9f77b | Home & Garden | $479.71 | 165 | ★ 3.0 | 73 | BULK-da1f89f9 |
| 7730 | Bulk Product 26c8d2d2 | Toys & Games | $717.27 | 491 | ★ 3.2 | 10 | BULK-09e461ec |
| 7731 | Bulk Product 2a85d743 | Books | $716.99 | 395 | ★ 2.0 | 14 | BULK-77220ff9 |
| 7732 | Bulk Product 598ef084 | Toys & Games | $691.19 | 120 | ★ 2.5 | 99 | BULK-a8c8ed80 |
| 7733 | Bulk Product 48092bc2 | Sports & Outdoors | $412.03 | 419 | ★ 2.6 | 18 | BULK-40082e31 |
| 7734 | Bulk Product dcd95174 | Home & Garden | $381.06 | 217 | ★ 2.2 | 8 | BULK-2626a4a3 |
// 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
};
}