Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 20510 | Bulk Product daf612cb | Toys & Games | $775.75 | 433 | ★ 3.1 | 23 | BULK-d2b48694 |
| 20511 | Bulk Product 90613caf | Clothing | $166.93 | 4 | ★ 4.1 | 60 | BULK-a2e3b978 |
| 20512 | Bulk Product cc45ac87 | Toys & Games | $592.07 | 211 | ★ 0.5 | 18 | BULK-46f37b6e |
| 20513 | Bulk Product 2e437ac7 | Books | $491.01 | 133 | ★ 3.6 | 97 | BULK-e5a95ed8 |
| 20514 | Bulk Product 34ce8244 | Electronics | $844.45 | 217 | ★ 0.3 | 26 | BULK-95ef52f5 |
| 20515 | Bulk Product c4b3f287 | Home & Garden | $703.05 | 316 | ★ 1.8 | 75 | BULK-676309ba |
| 20516 | Bulk Product 82afd7bc | Clothing | $282.65 | 413 | ★ 4.7 | 56 | BULK-076ee568 |
| 20517 | Bulk Product e6e64aa0 | Toys & Games | $478.68 | 452 | ★ 3.1 | 85 | BULK-2e6fa4f9 |
| 20518 | Bulk Product 010ef53f | Home & Garden | $164.61 | 10 | ★ 3.9 | 98 | BULK-a4807046 |
| 20519 | Bulk Product 19fc61cc | Books | $103.15 | 94 | ★ 2.6 | 66 | BULK-24feed9f |
| 20520 | Bulk Product 7a1290eb | Sports & Outdoors | $583.18 | 148 | ★ 5.0 | 27 | BULK-7b3139e7 |
| 20521 | Bulk Product bd522fad | Clothing | $226.70 | 452 | ★ 0.5 | 14 | BULK-cb379bd0 |
| 20522 | Bulk Product 99ebb46a | Sports & Outdoors | $262.09 | 411 | ★ 2.1 | 27 | BULK-f3256ea6 |
| 20523 | Bulk Product f17d5252 | Clothing | $431.08 | 166 | ★ 4.0 | 27 | BULK-6a9f8018 |
| 20524 | Bulk Product c3bfc443 | Books | $173.48 | 426 | ★ 4.6 | 81 | BULK-be32b70c |
| 20525 | Bulk Product bf1f49dc | Toys & Games | $851.11 | 387 | ★ 0.1 | 4 | BULK-1feed50c |
| 20526 | Bulk Product 076ccf83 | Home & Garden | $642.95 | 278 | ★ 3.5 | 41 | BULK-9f19621b |
| 20527 | Bulk Product 63aa28bd | Electronics | $440.73 | 216 | ★ 3.5 | 90 | BULK-117f2f12 |
| 20528 | Bulk Product 763d5904 | Electronics | $946.63 | 20 | ★ 3.5 | 94 | BULK-d12c1a44 |
| 20529 | Bulk Product 17f57d59 | Toys & Games | $253.44 | 138 | ★ 3.6 | 68 | BULK-bb394c30 |
| 20530 | Bulk Product a668d31b | Home & Garden | $55.58 | 136 | ★ 1.5 | 56 | BULK-b50748f7 |
| 20531 | Bulk Product 5f7bd939 | Clothing | $104.04 | 15 | ★ 0.6 | 19 | BULK-d678453a |
| 20532 | Bulk Product 682a3c82 | Toys & Games | $468.33 | 184 | ★ 1.9 | 89 | BULK-2391f3ff |
| 20533 | Bulk Product a2e9b743 | Home & Garden | $523.97 | 323 | ★ 3.6 | 99 | BULK-699b31ca |
| 20534 | Bulk Product 0b2fd878 | Sports & Outdoors | $134.38 | 227 | ★ 4.9 | 4 | BULK-058fb9e5 |
// 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
};
}