Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17710 | Bulk Product fbfff5df | Toys & Games | $427.62 | 101 | ★ 3.2 | 85 | BULK-f38f5597 |
| 17711 | Bulk Product 619dbc5e | Home & Garden | $441.35 | 104 | ★ 1.8 | 69 | BULK-1a41e6f8 |
| 17712 | Bulk Product e5d8885e | Clothing | $124.84 | 121 | ★ 2.9 | 75 | BULK-36b684af |
| 17713 | Bulk Product f2862fdb | Electronics | $264.41 | 308 | ★ 0.9 | 23 | BULK-80063a32 |
| 17714 | Bulk Product b1e2f642 | Electronics | $677.06 | 168 | ★ 3.3 | 47 | BULK-fd18b165 |
| 17715 | Bulk Product cfcdd464 | Books | $370.29 | 113 | ★ 1.7 | 18 | BULK-7f3fc129 |
| 17716 | Bulk Product 0d763c79 | Toys & Games | $608.15 | 172 | ★ 2.2 | 56 | BULK-bf0f5dde |
| 17717 | Bulk Product f08da7f5 | Books | $17.85 | 294 | ★ 2.6 | 19 | BULK-2130d7e3 |
| 17718 | Bulk Product fbc34052 | Clothing | $53.12 | 4 | ★ 3.6 | 72 | BULK-4a1147f6 |
| 17719 | Bulk Product 36ea0e83 | Clothing | $901.86 | 432 | ★ 0.7 | 46 | BULK-6e863104 |
| 17720 | Bulk Product 1228d4b3 | Clothing | $93.65 | 382 | ★ 5.0 | 92 | BULK-b475d93e |
| 17721 | Bulk Product a5d9a108 | Electronics | $54.31 | 82 | ★ 2.7 | 87 | BULK-688d58d9 |
| 17722 | Bulk Product 03a9deb4 | Books | $911.02 | 477 | ★ 2.8 | 86 | BULK-05506b5c |
| 17723 | Bulk Product 9a70eaac | Home & Garden | $980.99 | 114 | ★ 1.5 | 7 | BULK-13996307 |
| 17724 | Bulk Product 55b97fb4 | Toys & Games | $96.45 | 295 | ★ 3.7 | 65 | BULK-709e9e8c |
| 17725 | Bulk Product 34ee5d59 | Books | $148.35 | 190 | ★ 1.1 | 39 | BULK-20ec0f66 |
| 17726 | Bulk Product 793aff17 | Sports & Outdoors | $898.65 | 245 | ★ 2.6 | 4 | BULK-68cf0df1 |
| 17727 | Bulk Product a2172d74 | Books | $707.11 | 147 | ★ 0.8 | 76 | BULK-705fa563 |
| 17728 | Bulk Product fd3dd862 | Sports & Outdoors | $414.70 | 293 | ★ 1.0 | 71 | BULK-560702b5 |
| 17729 | Bulk Product 719def49 | Electronics | $557.99 | 357 | ★ 3.2 | 17 | BULK-c752f7b4 |
| 17730 | Bulk Product c14d8929 | Home & Garden | $470.05 | 227 | ★ 3.6 | 12 | BULK-f25827df |
| 17731 | Bulk Product c52db8f4 | Electronics | $620.49 | 179 | ★ 1.1 | 22 | BULK-25db8d4d |
| 17732 | Bulk Product 6f0c34c3 | Electronics | $645.61 | 478 | ★ 1.0 | 30 | BULK-3181c350 |
| 17733 | Bulk Product ae2c98be | Electronics | $325.41 | 351 | ★ 2.0 | 55 | BULK-d0cc267b |
| 17734 | Bulk Product f6cddfc7 | Books | $83.43 | 387 | ★ 5.0 | 74 | BULK-109d9c96 |
// 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
};
}