Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 24810 | Bulk Product 0e4fd70c | Sports & Outdoors | $192.28 | 150 | ★ 1.4 | 16 | BULK-774c56cb |
| 24811 | Bulk Product 08683da8 | Books | $13.55 | 80 | ★ 2.8 | 86 | BULK-7f950f01 |
| 24812 | Bulk Product f1255c6e | Electronics | $804.00 | 413 | ★ 0.1 | 90 | BULK-242f44f6 |
| 24813 | Bulk Product 459bda96 | Electronics | $235.57 | 434 | ★ 4.5 | 7 | BULK-d804f727 |
| 24814 | Bulk Product 2ba37fb3 | Sports & Outdoors | $28.36 | 184 | ★ 4.2 | 28 | BULK-d2d1a1a3 |
| 24815 | Bulk Product d8b2f526 | Electronics | $968.86 | 408 | ★ 4.6 | 4 | BULK-7d417db0 |
| 24816 | Bulk Product 9b3f1e3f | Books | $626.86 | 26 | ★ 1.4 | 66 | BULK-aeecafec |
| 24817 | Bulk Product 943116f1 | Electronics | $176.33 | 337 | ★ 2.5 | 71 | BULK-af6c4b7a |
| 24818 | Bulk Product 813e4b9f | Toys & Games | $340.16 | 115 | ★ 0.6 | 24 | BULK-c797499e |
| 24819 | Bulk Product 3e191778 | Electronics | $231.35 | 350 | ★ 0.5 | 91 | BULK-50e8e35a |
| 24820 | Bulk Product b6310b61 | Electronics | $729.87 | 406 | ★ 0.3 | 44 | BULK-d542c561 |
| 24821 | Bulk Product ab9f9eff | Books | $665.25 | 372 | ★ 4.2 | 32 | BULK-fbf860fc |
| 24822 | Bulk Product 9aaf7609 | Home & Garden | $178.72 | 456 | ★ 2.1 | 7 | BULK-71761a6a |
| 24823 | Bulk Product e911d61d | Toys & Games | $634.38 | 126 | ★ 1.7 | 53 | BULK-dba464b5 |
| 24824 | Bulk Product a4870488 | Sports & Outdoors | $109.06 | 301 | ★ 1.0 | 22 | BULK-57a1e824 |
| 24825 | Bulk Product 64eaedc8 | Sports & Outdoors | $671.89 | 330 | ★ 1.3 | 45 | BULK-71f1f09e |
| 24826 | Bulk Product 92012c5b | Clothing | $528.14 | 297 | ★ 4.4 | 31 | BULK-743fd3d4 |
| 24827 | Bulk Product 5d3e3cf8 | Books | $86.14 | 97 | ★ 3.0 | 11 | BULK-180e237f |
| 24828 | Bulk Product 1b2c6e87 | Toys & Games | $909.01 | 46 | ★ 0.7 | 43 | BULK-f3b3126c |
| 24829 | Bulk Product b9775a3f | Clothing | $324.46 | 486 | ★ 4.0 | 77 | BULK-e98640d1 |
| 24830 | Bulk Product 62cb264d | Sports & Outdoors | $525.39 | 11 | ★ 3.4 | 27 | BULK-5c0f2460 |
| 24831 | Bulk Product bbf8bcfa | Electronics | $901.09 | 218 | ★ 0.3 | 95 | BULK-42fa790d |
| 24832 | Bulk Product b30cef41 | Home & Garden | $81.48 | 447 | ★ 4.8 | 19 | BULK-4030cd45 |
| 24833 | Bulk Product 9993250f | Clothing | $288.34 | 379 | ★ 4.8 | 73 | BULK-d9a63df7 |
| 24834 | Bulk Product 051a05e6 | Sports & Outdoors | $49.24 | 230 | ★ 3.7 | 74 | BULK-dd2f3483 |
// 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
};
}