Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 11435 | Bulk Product 7cac69c7 | Home & Garden | $33.07 | 285 | ★ 0.0 | 97 | BULK-cedd18a6 |
| 11436 | Bulk Product 54e7cfca | Clothing | $714.42 | 171 | ★ 1.8 | 40 | BULK-1c14d0af |
| 11437 | Bulk Product b3dc45b3 | Toys & Games | $258.12 | 179 | ★ 4.8 | 63 | BULK-f3934e6f |
| 11438 | Bulk Product 051efc6b | Toys & Games | $987.30 | 146 | ★ 0.8 | 14 | BULK-1f6f0d42 |
| 11439 | Bulk Product 876e2da4 | Books | $995.43 | 211 | ★ 3.6 | 11 | BULK-83654864 |
| 11440 | Bulk Product b7cfa950 | Electronics | $930.05 | 317 | ★ 3.9 | 78 | BULK-eaabf91b |
| 11441 | Bulk Product a05f8c3c | Electronics | $21.36 | 61 | ★ 1.5 | 57 | BULK-eee99414 |
| 11442 | Bulk Product 2ebb4770 | Toys & Games | $464.01 | 215 | ★ 3.5 | 64 | BULK-975e70c3 |
| 11443 | Bulk Product 6d30ca23 | Electronics | $341.35 | 372 | ★ 2.4 | 3 | BULK-8c909ac2 |
| 11444 | Bulk Product e56f146f | Toys & Games | $21.51 | 108 | ★ 4.8 | 70 | BULK-65c02495 |
| 11445 | Bulk Product 1b522876 | Toys & Games | $76.76 | 16 | ★ 2.3 | 5 | BULK-8c4055a4 |
| 11446 | Bulk Product 393ae474 | Toys & Games | $669.17 | 282 | ★ 0.6 | 0 | BULK-f786b893 |
| 11447 | Bulk Product 424676c2 | Electronics | $200.53 | 27 | ★ 1.0 | 28 | BULK-e3303645 |
| 11448 | Bulk Product 49746424 | Clothing | $87.12 | 407 | ★ 0.2 | 35 | BULK-6f5d238d |
| 11449 | Bulk Product d104d861 | Books | $618.80 | 177 | ★ 2.2 | 64 | BULK-188c39b5 |
| 11450 | Bulk Product ed76530d | Electronics | $728.86 | 387 | ★ 0.1 | 89 | BULK-9d936bb6 |
| 11451 | Bulk Product 459ac9d8 | Home & Garden | $447.54 | 58 | ★ 4.7 | 51 | BULK-0c7416d7 |
| 11452 | Bulk Product aa9cbec7 | Toys & Games | $445.96 | 109 | ★ 1.6 | 61 | BULK-b2c743d3 |
| 11453 | Bulk Product db86786d | Books | $795.63 | 364 | ★ 4.6 | 14 | BULK-74ff8eca |
| 11454 | Bulk Product 5cfbf037 | Electronics | $965.61 | 492 | ★ 4.7 | 11 | BULK-8f48d53d |
| 11455 | Bulk Product 7e61ae3f | Sports & Outdoors | $849.72 | 381 | ★ 4.5 | 94 | BULK-42783462 |
| 11456 | Bulk Product e860eb48 | Clothing | $110.54 | 142 | ★ 2.2 | 77 | BULK-7d77db65 |
| 11457 | Bulk Product d7bca694 | Sports & Outdoors | $754.59 | 154 | ★ 3.5 | 12 | BULK-6a8a0324 |
| 11458 | Bulk Product 76e29002 | Books | $582.28 | 275 | ★ 3.5 | 75 | BULK-f640d350 |
| 11459 | Bulk Product 71e49bf7 | Toys & Games | $940.00 | 166 | ★ 4.6 | 98 | BULK-e574e3a3 |
// 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
};
}