Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 7060 | Bulk Product 0b8a70dd | Clothing | $277.80 | 407 | ★ 0.5 | 91 | BULK-6fa048d9 |
| 7061 | Bulk Product 328a1b10 | Toys & Games | $641.80 | 461 | ★ 1.7 | 59 | BULK-c140a353 |
| 7062 | Bulk Product 0e5bcb40 | Sports & Outdoors | $406.62 | 425 | ★ 0.7 | 46 | BULK-7cbe4286 |
| 7063 | Bulk Product df3c6f8f | Toys & Games | $845.95 | 112 | ★ 1.1 | 18 | BULK-a2c36e78 |
| 7064 | Bulk Product 72f4df17 | Toys & Games | $32.55 | 464 | ★ 3.7 | 46 | BULK-34ffa7d1 |
| 7065 | Bulk Product 2adb2162 | Electronics | $192.40 | 95 | ★ 4.6 | 35 | BULK-a49f2f29 |
| 7066 | Bulk Product 9a2d9b5d | Electronics | $313.34 | 494 | ★ 3.2 | 95 | BULK-91837928 |
| 7067 | Bulk Product 037ab882 | Clothing | $382.92 | 236 | ★ 1.5 | 40 | BULK-69d2a2de |
| 7068 | Bulk Product 26f8445c | Toys & Games | $387.52 | 285 | ★ 4.1 | 9 | BULK-3037ee8f |
| 7069 | Bulk Product d4fb363e | Home & Garden | $705.38 | 170 | ★ 0.2 | 8 | BULK-6dac3b29 |
| 7070 | Bulk Product 025d0534 | Sports & Outdoors | $692.05 | 84 | ★ 2.8 | 54 | BULK-d11abc62 |
| 7071 | Bulk Product 5ba4ed0e | Toys & Games | $838.19 | 381 | ★ 0.5 | 58 | BULK-5eba1f24 |
| 7072 | Bulk Product addb6135 | Books | $184.63 | 177 | ★ 3.3 | 90 | BULK-e2e4e69b |
| 7073 | Bulk Product 2a28a92a | Books | $339.18 | 81 | ★ 4.3 | 96 | BULK-24955357 |
| 7074 | Bulk Product 9b43445f | Electronics | $126.52 | 99 | ★ 3.4 | 51 | BULK-038286c3 |
| 7075 | Bulk Product a896d667 | Books | $780.25 | 459 | ★ 2.6 | 22 | BULK-8d0aa011 |
| 7076 | Bulk Product 10c5741c | Electronics | $969.14 | 196 | ★ 4.3 | 79 | BULK-d1a71358 |
| 7077 | Bulk Product 19c0c854 | Clothing | $76.17 | 407 | ★ 3.4 | 13 | BULK-aba104a7 |
| 7078 | Bulk Product 691075fa | Clothing | $429.91 | 161 | ★ 3.3 | 78 | BULK-6f269fef |
| 7079 | Bulk Product b370acdb | Books | $782.32 | 393 | ★ 2.8 | 96 | BULK-57e1f976 |
| 7080 | Bulk Product 29427c15 | Electronics | $154.25 | 192 | ★ 2.3 | 35 | BULK-c31f74d1 |
| 7081 | Bulk Product 967879e1 | Home & Garden | $793.81 | 497 | ★ 0.1 | 1 | BULK-de35f140 |
| 7082 | Bulk Product c5ce00fa | Sports & Outdoors | $484.81 | 356 | ★ 1.1 | 6 | BULK-311850b3 |
| 7083 | Bulk Product dd33570f | Books | $768.24 | 357 | ★ 2.1 | 27 | BULK-463df44d |
| 7084 | Bulk Product ffa2e4c1 | Sports & Outdoors | $752.98 | 63 | ★ 2.8 | 45 | BULK-8e2be215 |
// 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
};
}