Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 19285 | Bulk Product bab46379 | Books | $868.87 | 218 | ★ 0.3 | 45 | BULK-97c18bce |
| 19286 | Bulk Product f25df581 | Books | $714.52 | 226 | ★ 2.9 | 36 | BULK-8fd28ae2 |
| 19287 | Bulk Product fb3bfe22 | Clothing | $897.17 | 152 | ★ 3.5 | 31 | BULK-6af09d87 |
| 19288 | Bulk Product 49863ec4 | Toys & Games | $419.95 | 167 | ★ 3.4 | 39 | BULK-0c2891f9 |
| 19289 | Bulk Product 45b56c2b | Clothing | $392.28 | 490 | ★ 1.4 | 28 | BULK-b01b8289 |
| 19290 | Bulk Product cc3aeeb4 | Toys & Games | $335.55 | 200 | ★ 1.3 | 28 | BULK-c6d60591 |
| 19291 | Bulk Product 9dedd9d3 | Books | $132.54 | 444 | ★ 3.6 | 31 | BULK-50484f61 |
| 19292 | Bulk Product 849d057d | Sports & Outdoors | $196.96 | 473 | ★ 4.3 | 56 | BULK-dba3fd13 |
| 19293 | Bulk Product dc869cb1 | Sports & Outdoors | $825.87 | 447 | ★ 1.8 | 48 | BULK-024597c1 |
| 19294 | Bulk Product 78f41ffb | Toys & Games | $254.08 | 176 | ★ 0.4 | 84 | BULK-7f575316 |
| 19295 | Bulk Product 6131a734 | Electronics | $568.41 | 170 | ★ 2.8 | 75 | BULK-3f2e9785 |
| 19296 | Bulk Product a9f111db | Electronics | $816.52 | 75 | ★ 1.5 | 59 | BULK-c40373c7 |
| 19297 | Bulk Product 11d67012 | Clothing | $941.83 | 39 | ★ 4.7 | 43 | BULK-f722ca1a |
| 19298 | Bulk Product c3d73bab | Electronics | $299.05 | 493 | ★ 1.6 | 69 | BULK-7aac6ede |
| 19299 | Bulk Product 31ddf324 | Electronics | $223.20 | 477 | ★ 3.7 | 63 | BULK-de6304b9 |
| 19300 | Bulk Product eaab985e | Toys & Games | $338.82 | 117 | ★ 4.3 | 58 | BULK-26d7c3b6 |
| 19301 | Bulk Product 2d8743f6 | Electronics | $480.20 | 154 | ★ 1.9 | 40 | BULK-74d347a1 |
| 19302 | Bulk Product facc958d | Sports & Outdoors | $282.73 | 138 | ★ 1.9 | 45 | BULK-9463a6dd |
| 19303 | Bulk Product 24df5497 | Electronics | $518.82 | 260 | ★ 3.6 | 60 | BULK-f3b51c4f |
| 19304 | Bulk Product 4f13683a | Books | $50.41 | 433 | ★ 1.4 | 16 | BULK-e65b4bd1 |
| 19305 | Bulk Product fcba1041 | Books | $986.41 | 302 | ★ 4.9 | 50 | BULK-ec63d858 |
| 19306 | Bulk Product bf430c97 | Toys & Games | $308.21 | 267 | ★ 3.0 | 10 | BULK-e9639179 |
| 19307 | Bulk Product 3149d422 | Electronics | $914.50 | 358 | ★ 1.3 | 20 | BULK-8ec378b0 |
| 19308 | Bulk Product 1e3bca6d | Electronics | $413.36 | 75 | ★ 0.5 | 88 | BULK-f700491e |
| 19309 | Bulk Product d0bc243a | Electronics | $100.69 | 133 | ★ 4.3 | 73 | BULK-ef476533 |
// 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
};
}