Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 14810 | Bulk Product db1da3b8 | Books | $973.64 | 18 | ★ 3.1 | 7 | BULK-33c70c8f |
| 14811 | Bulk Product ee39fc82 | Home & Garden | $784.94 | 465 | ★ 1.1 | 92 | BULK-6d1c1c20 |
| 14812 | Bulk Product 51604b81 | Clothing | $881.54 | 345 | ★ 2.4 | 13 | BULK-581295ed |
| 14813 | Bulk Product f5933bf2 | Home & Garden | $53.80 | 170 | ★ 4.0 | 52 | BULK-b8210e68 |
| 14814 | Bulk Product 4de17ed8 | Toys & Games | $769.12 | 36 | ★ 1.1 | 87 | BULK-b1d07aba |
| 14815 | Bulk Product 1b96f271 | Electronics | $409.69 | 94 | ★ 3.4 | 9 | BULK-f2976d34 |
| 14816 | Bulk Product d423ef3d | Home & Garden | $974.64 | 196 | ★ 4.1 | 72 | BULK-593ff0a6 |
| 14817 | Bulk Product f7f12f98 | Toys & Games | $743.79 | 168 | ★ 2.1 | 87 | BULK-7bd6fd88 |
| 14818 | Bulk Product 3c81569c | Books | $292.46 | 122 | ★ 3.8 | 87 | BULK-3da459e8 |
| 14819 | Bulk Product 6baea431 | Books | $662.38 | 282 | ★ 2.9 | 15 | BULK-48199a12 |
| 14820 | Bulk Product e334e32a | Toys & Games | $259.02 | 326 | ★ 0.1 | 37 | BULK-dbc16e93 |
| 14821 | Bulk Product 1458e0ac | Toys & Games | $19.15 | 216 | ★ 4.8 | 33 | BULK-03cd9d65 |
| 14822 | Bulk Product f71d4914 | Home & Garden | $78.13 | 439 | ★ 4.2 | 52 | BULK-d2fdba32 |
| 14823 | Bulk Product 0a22d601 | Clothing | $478.18 | 400 | ★ 4.0 | 12 | BULK-7fca3a0f |
| 14824 | Bulk Product 60b826dd | Electronics | $131.44 | 8 | ★ 2.9 | 27 | BULK-bad92359 |
| 14825 | Bulk Product 8053eb3b | Electronics | $967.51 | 291 | ★ 2.9 | 34 | BULK-3fe62172 |
| 14826 | Bulk Product bf7ad24a | Clothing | $920.55 | 14 | ★ 1.8 | 56 | BULK-e4d18d41 |
| 14827 | Bulk Product a032a40c | Electronics | $375.65 | 191 | ★ 3.2 | 48 | BULK-bd8275d7 |
| 14828 | Bulk Product 1cc5b139 | Electronics | $69.81 | 96 | ★ 0.0 | 91 | BULK-396ef9be |
| 14829 | Bulk Product 7d53ee16 | Clothing | $782.58 | 405 | ★ 4.8 | 7 | BULK-4a02c86d |
| 14830 | Bulk Product 9e80dc0f | Home & Garden | $928.01 | 46 | ★ 2.3 | 50 | BULK-b0aedab4 |
| 14831 | Bulk Product 0afadf3d | Electronics | $355.33 | 391 | ★ 4.0 | 40 | BULK-a9bc3651 |
| 14832 | Bulk Product 8bc3694f | Toys & Games | $788.63 | 198 | ★ 1.9 | 61 | BULK-5a182164 |
| 14833 | Bulk Product 65f3465a | Books | $534.26 | 38 | ★ 2.0 | 13 | BULK-81add11e |
| 14834 | Bulk Product 90ae9649 | Clothing | $674.16 | 214 | ★ 3.4 | 59 | BULK-8da65df3 |
// 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
};
}