Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17635 | Bulk Product d26c1783 | Toys & Games | $775.58 | 141 | ★ 3.9 | 48 | BULK-b2ec933e |
| 17636 | Bulk Product 4671006f | Clothing | $803.45 | 327 | ★ 1.0 | 31 | BULK-cbde6e5a |
| 17637 | Bulk Product 23fcd9a2 | Sports & Outdoors | $119.82 | 51 | ★ 4.5 | 23 | BULK-56727b2d |
| 17638 | Bulk Product fd9b9db4 | Clothing | $568.45 | 386 | ★ 4.9 | 19 | BULK-d3f00d69 |
| 17639 | Bulk Product 3805600d | Home & Garden | $559.59 | 49 | ★ 0.1 | 64 | BULK-1da5103a |
| 17640 | Bulk Product 2060348a | Home & Garden | $978.43 | 50 | ★ 2.1 | 36 | BULK-11ef1df2 |
| 17641 | Bulk Product 4ee545ca | Sports & Outdoors | $804.14 | 464 | ★ 2.5 | 47 | BULK-7fd27dfc |
| 17642 | Bulk Product c13b859c | Sports & Outdoors | $528.17 | 335 | ★ 0.8 | 67 | BULK-e26ea500 |
| 17643 | Bulk Product fe09c100 | Sports & Outdoors | $84.35 | 447 | ★ 0.4 | 72 | BULK-5290540b |
| 17644 | Bulk Product d33ffc1b | Sports & Outdoors | $137.75 | 179 | ★ 0.2 | 65 | BULK-dcbe4b2a |
| 17645 | Bulk Product afd062db | Electronics | $361.45 | 306 | ★ 0.4 | 45 | BULK-b03f1d7a |
| 17646 | Bulk Product 0a04072d | Home & Garden | $460.58 | 290 | ★ 2.8 | 37 | BULK-4047f89b |
| 17647 | Bulk Product eeb194ce | Toys & Games | $297.85 | 92 | ★ 1.2 | 81 | BULK-82881318 |
| 17648 | Bulk Product 113d4731 | Toys & Games | $341.22 | 33 | ★ 0.8 | 10 | BULK-afd4a8ad |
| 17649 | Bulk Product eff0f7d7 | Home & Garden | $681.09 | 356 | ★ 3.4 | 42 | BULK-ef947ea0 |
| 17650 | Bulk Product 32188ab3 | Electronics | $183.92 | 32 | ★ 3.8 | 92 | BULK-c11fe299 |
| 17651 | Bulk Product a98999c8 | Toys & Games | $979.37 | 381 | ★ 4.9 | 13 | BULK-020ee4d9 |
| 17652 | Bulk Product 2807364e | Home & Garden | $311.53 | 66 | ★ 4.6 | 29 | BULK-c2b447b9 |
| 17653 | Bulk Product 1a4514d6 | Clothing | $77.24 | 340 | ★ 2.0 | 49 | BULK-79761f85 |
| 17654 | Bulk Product e9fc308d | Clothing | $110.18 | 347 | ★ 0.6 | 90 | BULK-e186f04a |
| 17655 | Bulk Product 6a2f4dd6 | Toys & Games | $331.75 | 480 | ★ 1.1 | 23 | BULK-e00971c0 |
| 17656 | Bulk Product a15c95a5 | Sports & Outdoors | $540.24 | 149 | ★ 3.0 | 79 | BULK-7404d411 |
| 17657 | Bulk Product 251979e4 | Toys & Games | $974.62 | 457 | ★ 4.7 | 77 | BULK-760bd35d |
| 17658 | Bulk Product 3764a8dc | Clothing | $853.16 | 40 | ★ 0.9 | 10 | BULK-6188f6d2 |
| 17659 | Bulk Product efec2f2f | Clothing | $616.47 | 310 | ★ 1.0 | 35 | BULK-ed9d6842 |
// 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
};
}