Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 6285 | Bulk Product 11327e73 | Books | $432.31 | 429 | ★ 0.1 | 92 | BULK-e0825f4e |
| 6286 | Bulk Product 9f6bb94e | Electronics | $110.70 | 323 | ★ 3.1 | 40 | BULK-8ff474f2 |
| 6287 | Bulk Product d788283d | Home & Garden | $963.66 | 31 | ★ 3.6 | 30 | BULK-ac5c352a |
| 6288 | Bulk Product 5406e2fd | Clothing | $86.78 | 151 | ★ 4.2 | 24 | BULK-1535d3d5 |
| 6289 | Bulk Product 536d3f35 | Toys & Games | $555.80 | 311 | ★ 1.7 | 15 | BULK-254cca24 |
| 6290 | Bulk Product cfb26f97 | Books | $435.98 | 493 | ★ 1.7 | 2 | BULK-0c735dcd |
| 6291 | Bulk Product 2fdbdda6 | Clothing | $510.21 | 332 | ★ 1.7 | 79 | BULK-a11d0586 |
| 6292 | Bulk Product ca88c6bf | Clothing | $14.72 | 19 | ★ 2.0 | 63 | BULK-391b2958 |
| 6293 | Bulk Product 3812d738 | Sports & Outdoors | $645.80 | 293 | ★ 2.2 | 52 | BULK-f3458ee2 |
| 6294 | Bulk Product 034a4a42 | Electronics | $446.79 | 410 | ★ 3.2 | 46 | BULK-39147c36 |
| 6295 | Bulk Product dac6f94b | Clothing | $498.21 | 198 | ★ 4.8 | 81 | BULK-ea952c80 |
| 6296 | Bulk Product ba7b000c | Sports & Outdoors | $238.79 | 382 | ★ 1.0 | 96 | BULK-d5ac3372 |
| 6297 | Bulk Product f602e290 | Clothing | $331.77 | 400 | ★ 3.8 | 46 | BULK-767e0b93 |
| 6298 | Bulk Product f45f48f1 | Electronics | $752.92 | 473 | ★ 2.0 | 41 | BULK-32fb341f |
| 6299 | Bulk Product 86cebcfb | Electronics | $488.20 | 329 | ★ 4.0 | 92 | BULK-afdd9f17 |
| 6300 | Bulk Product 5eeb7fb9 | Electronics | $935.71 | 166 | ★ 2.5 | 45 | BULK-5149a6ad |
| 6301 | Bulk Product 2624fe41 | Sports & Outdoors | $808.28 | 140 | ★ 1.7 | 64 | BULK-bdc55c5d |
| 6302 | Bulk Product 2b5d66c5 | Toys & Games | $214.02 | 272 | ★ 1.9 | 47 | BULK-c635605f |
| 6303 | Bulk Product 24509f4b | Clothing | $33.14 | 415 | ★ 4.1 | 24 | BULK-ad9d28fa |
| 6304 | Bulk Product def083cd | Electronics | $442.95 | 357 | ★ 2.3 | 72 | BULK-ff729633 |
| 6305 | Bulk Product 42fa54c5 | Toys & Games | $863.59 | 393 | ★ 2.8 | 73 | BULK-a373b7e6 |
| 6306 | Bulk Product b9e1d04a | Electronics | $134.24 | 224 | ★ 0.6 | 67 | BULK-51c133f2 |
| 6307 | Bulk Product 544a85ab | Toys & Games | $445.36 | 324 | ★ 4.2 | 80 | BULK-af9191da |
| 6308 | Bulk Product 8de64356 | Books | $516.27 | 144 | ★ 4.5 | 36 | BULK-2f39acf2 |
| 6309 | Bulk Product f97dba9e | Sports & Outdoors | $884.52 | 374 | ★ 1.4 | 72 | BULK-e1410ffc |
// 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
};
}