Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 14160 | Bulk Product 423e4660 | Home & Garden | $575.46 | 441 | ★ 1.1 | 22 | BULK-ca9d778c |
| 14161 | Bulk Product c9ee8800 | Clothing | $86.87 | 447 | ★ 0.2 | 77 | BULK-36be7a53 |
| 14162 | Bulk Product 1ecde961 | Sports & Outdoors | $469.18 | 289 | ★ 4.1 | 96 | BULK-16950ce6 |
| 14163 | Bulk Product 819f3f8e | Sports & Outdoors | $299.17 | 49 | ★ 5.0 | 24 | BULK-569b00ea |
| 14164 | Bulk Product e5d51a91 | Home & Garden | $343.31 | 8 | ★ 1.1 | 42 | BULK-8467ee14 |
| 14165 | Bulk Product 2b91af4f | Clothing | $240.54 | 140 | ★ 0.1 | 12 | BULK-39213905 |
| 14166 | Bulk Product 9b667205 | Sports & Outdoors | $908.17 | 121 | ★ 2.6 | 95 | BULK-3e018e62 |
| 14167 | Bulk Product e39e7923 | Clothing | $594.77 | 312 | ★ 0.7 | 51 | BULK-34aaeefe |
| 14168 | Bulk Product cbc20e8c | Clothing | $474.43 | 65 | ★ 1.7 | 67 | BULK-02cc5569 |
| 14169 | Bulk Product 8bec3998 | Sports & Outdoors | $997.64 | 456 | ★ 0.4 | 95 | BULK-41fa57e4 |
| 14170 | Bulk Product 8dbee59a | Sports & Outdoors | $482.51 | 64 | ★ 3.8 | 27 | BULK-b87c7bd6 |
| 14171 | Bulk Product 97f50580 | Electronics | $137.51 | 215 | ★ 2.1 | 53 | BULK-b6da96ef |
| 14172 | Bulk Product a864fdb0 | Electronics | $943.18 | 459 | ★ 1.4 | 27 | BULK-ff3d83b0 |
| 14173 | Bulk Product f9377bc2 | Home & Garden | $599.56 | 127 | ★ 0.0 | 90 | BULK-09e62235 |
| 14174 | Bulk Product 787ca5ff | Toys & Games | $865.81 | 472 | ★ 3.3 | 78 | BULK-2b6dd081 |
| 14175 | Bulk Product 57352bd8 | Electronics | $229.33 | 197 | ★ 0.8 | 69 | BULK-a3b7b2fc |
| 14176 | Bulk Product a2e06df8 | Toys & Games | $277.99 | 320 | ★ 1.0 | 89 | BULK-9c6e75f3 |
| 14177 | Bulk Product 853df818 | Electronics | $85.98 | 324 | ★ 1.6 | 27 | BULK-3bfbbe51 |
| 14178 | Bulk Product 2b6034ab | Home & Garden | $507.61 | 57 | ★ 2.9 | 87 | BULK-71ce7fe6 |
| 14179 | Bulk Product c85e7387 | Books | $535.66 | 443 | ★ 1.4 | 31 | BULK-ebd42d35 |
| 14180 | Bulk Product e705a3d4 | Books | $620.74 | 262 | ★ 0.0 | 13 | BULK-f5956aae |
| 14181 | Bulk Product 0692ff13 | Books | $391.47 | 474 | ★ 4.4 | 60 | BULK-94cb954c |
| 14182 | Bulk Product 500de276 | Toys & Games | $643.37 | 410 | ★ 3.9 | 14 | BULK-ff862caf |
| 14183 | Bulk Product cf7b7b30 | Toys & Games | $781.30 | 193 | ★ 1.0 | 82 | BULK-305a88f7 |
| 14184 | Bulk Product f2c8fd3f | Toys & Games | $450.06 | 25 | ★ 2.7 | 66 | BULK-7653ad8d |
// 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
};
}