Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5835 | Bulk Product 984a2e45 | Books | $713.73 | 132 | ★ 4.6 | 93 | BULK-9b799644 |
| 5836 | Bulk Product 7ff0072e | Home & Garden | $442.78 | 274 | ★ 2.0 | 94 | BULK-a92f624e |
| 5837 | Bulk Product b9616610 | Home & Garden | $516.41 | 98 | ★ 2.4 | 72 | BULK-12abe594 |
| 5838 | Bulk Product 7f1e96ba | Electronics | $383.91 | 140 | ★ 3.7 | 31 | BULK-64db1079 |
| 5839 | Bulk Product bc96e5d0 | Home & Garden | $921.28 | 289 | ★ 4.8 | 10 | BULK-6de2742b |
| 5840 | Bulk Product 761e8319 | Books | $127.42 | 372 | ★ 0.8 | 81 | BULK-5fd8ff6c |
| 5841 | Bulk Product ffbe5021 | Electronics | $405.89 | 462 | ★ 2.0 | 99 | BULK-a034ca10 |
| 5842 | Bulk Product 5798926d | Toys & Games | $358.21 | 115 | ★ 2.1 | 71 | BULK-419559ca |
| 5843 | Bulk Product 6664b265 | Home & Garden | $411.26 | 100 | ★ 2.6 | 14 | BULK-5a7ac7eb |
| 5844 | Bulk Product 9d25fe44 | Electronics | $144.91 | 220 | ★ 4.1 | 75 | BULK-1f0a7c65 |
| 5845 | Bulk Product a9c07484 | Electronics | $803.70 | 305 | ★ 0.9 | 37 | BULK-2f3b8c3c |
| 5846 | Bulk Product 4b0365f5 | Sports & Outdoors | $760.23 | 65 | ★ 0.4 | 20 | BULK-d69ed0d6 |
| 5847 | Bulk Product a243c3e0 | Sports & Outdoors | $633.08 | 389 | ★ 3.3 | 19 | BULK-d4b98feb |
| 5848 | Bulk Product c3b617c6 | Clothing | $641.17 | 342 | ★ 2.9 | 65 | BULK-1eda441c |
| 5849 | Bulk Product b72f3717 | Toys & Games | $498.50 | 416 | ★ 2.3 | 42 | BULK-62e6d262 |
| 5850 | Bulk Product f42d5ace | Clothing | $622.17 | 401 | ★ 4.5 | 90 | BULK-716be5f9 |
| 5851 | Bulk Product 394bbd4e | Electronics | $477.55 | 433 | ★ 3.2 | 7 | BULK-06bc26fd |
| 5852 | Bulk Product 0a85780f | Clothing | $342.35 | 172 | ★ 1.3 | 21 | BULK-96588dc9 |
| 5853 | Bulk Product f07a3e0a | Electronics | $241.05 | 323 | ★ 0.3 | 7 | BULK-39233b15 |
| 5854 | Bulk Product 19fe10b6 | Electronics | $555.93 | 266 | ★ 0.9 | 12 | BULK-772fb2ad |
| 5855 | Bulk Product 99654c93 | Clothing | $502.49 | 314 | ★ 1.4 | 80 | BULK-bbeb8f04 |
| 5856 | Bulk Product a06f12d0 | Books | $810.48 | 231 | ★ 4.1 | 25 | BULK-d281b448 |
| 5857 | Bulk Product e91f65d6 | Sports & Outdoors | $601.71 | 436 | ★ 3.8 | 29 | BULK-55a3285f |
| 5858 | Bulk Product 353c4e1e | Electronics | $414.38 | 466 | ★ 0.1 | 92 | BULK-ee702427 |
| 5859 | Bulk Product 75e1c25e | Electronics | $974.41 | 106 | ★ 0.4 | 97 | BULK-5320c0a1 |
// 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
};
}