Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 10010 | Bulk Product 6c81725b | Clothing | $570.37 | 19 | ★ 3.0 | 77 | BULK-c98149f0 |
| 10011 | Bulk Product 8d89c352 | Toys & Games | $864.78 | 246 | ★ 1.2 | 41 | BULK-e7384aeb |
| 10012 | Bulk Product 61e1e7ea | Clothing | $74.02 | 43 | ★ 2.2 | 86 | BULK-ba74023a |
| 10013 | Bulk Product 269aabe9 | Sports & Outdoors | $220.93 | 214 | ★ 1.9 | 3 | BULK-a4dc98a4 |
| 10014 | Bulk Product 651cc72e | Home & Garden | $742.20 | 33 | ★ 3.9 | 98 | BULK-e4284f1b |
| 10015 | Bulk Product a9fe443d | Sports & Outdoors | $190.73 | 297 | ★ 2.7 | 92 | BULK-19d242dc |
| 10016 | Bulk Product d1bb35b1 | Clothing | $144.39 | 81 | ★ 1.0 | 7 | BULK-91731ec8 |
| 10017 | Bulk Product 447bc894 | Sports & Outdoors | $664.85 | 499 | ★ 3.7 | 52 | BULK-3364dba1 |
| 10018 | Bulk Product 1a2abf56 | Electronics | $410.51 | 403 | ★ 4.0 | 29 | BULK-ddeb8773 |
| 10019 | Bulk Product 0c67b0e5 | Sports & Outdoors | $967.67 | 330 | ★ 5.0 | 22 | BULK-f2028bdc |
| 10020 | Bulk Product 6b1e6f81 | Books | $405.41 | 409 | ★ 4.4 | 10 | BULK-7a5df586 |
| 10021 | Bulk Product af32b2ca | Clothing | $290.13 | 449 | ★ 2.5 | 99 | BULK-32fc5475 |
| 10022 | Bulk Product 104ec175 | Electronics | $387.83 | 173 | ★ 1.6 | 0 | BULK-82667380 |
| 10023 | Bulk Product a402da52 | Clothing | $67.53 | 449 | ★ 3.9 | 64 | BULK-5294b4fd |
| 10024 | Bulk Product ae77d298 | Sports & Outdoors | $314.65 | 354 | ★ 4.1 | 44 | BULK-11d67b1b |
| 10025 | Bulk Product 37bdcf77 | Clothing | $884.73 | 8 | ★ 4.4 | 89 | BULK-7f2a65f0 |
| 10026 | Bulk Product 6fd0abbb | Sports & Outdoors | $826.53 | 408 | ★ 4.8 | 93 | BULK-4e2ecb05 |
| 10027 | Bulk Product 49ee37bf | Home & Garden | $502.23 | 382 | ★ 0.0 | 10 | BULK-4a37dbe6 |
| 10028 | Bulk Product 83895b9e | Electronics | $267.11 | 155 | ★ 2.4 | 99 | BULK-a3a896eb |
| 10029 | Bulk Product 56651955 | Toys & Games | $219.98 | 148 | ★ 0.8 | 59 | BULK-947749f6 |
| 10030 | Bulk Product 230f54ec | Home & Garden | $433.42 | 133 | ★ 1.8 | 43 | BULK-fbb6a73f |
| 10031 | Bulk Product 1dffa62a | Toys & Games | $426.46 | 201 | ★ 2.6 | 54 | BULK-252c4b0f |
| 10032 | Bulk Product 1dccce97 | Books | $393.48 | 219 | ★ 2.5 | 1 | BULK-724619cf |
| 10033 | Bulk Product 6e693aa9 | Sports & Outdoors | $677.57 | 21 | ★ 3.2 | 91 | BULK-70d65faf |
| 10034 | Bulk Product 798f0dba | Books | $963.42 | 120 | ★ 4.1 | 38 | BULK-eb6caf7a |
// 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
};
}