Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 18710 | Bulk Product 254c19b6 | Toys & Games | $730.51 | 443 | ★ 2.3 | 47 | BULK-e6310030 |
| 18711 | Bulk Product 5e5f9b83 | Books | $300.11 | 462 | ★ 1.3 | 28 | BULK-ec881feb |
| 18712 | Bulk Product 9fa5a9f5 | Home & Garden | $841.95 | 483 | ★ 3.9 | 16 | BULK-db7ffbbe |
| 18713 | Bulk Product 5f812b59 | Books | $418.81 | 88 | ★ 1.6 | 55 | BULK-67f4ae88 |
| 18714 | Bulk Product 598d0207 | Books | $562.93 | 137 | ★ 3.2 | 17 | BULK-d01fabe4 |
| 18715 | Bulk Product 61b17290 | Toys & Games | $169.56 | 116 | ★ 3.3 | 62 | BULK-ed338bf7 |
| 18716 | Bulk Product b43c6f8f | Books | $332.22 | 462 | ★ 4.3 | 59 | BULK-a310798a |
| 18717 | Bulk Product 760f594c | Sports & Outdoors | $175.53 | 376 | ★ 0.8 | 39 | BULK-e77f1b5b |
| 18718 | Bulk Product 380dd0f4 | Sports & Outdoors | $583.62 | 233 | ★ 3.2 | 63 | BULK-32b979cc |
| 18719 | Bulk Product a9329b1c | Toys & Games | $1,003.70 | 419 | ★ 1.2 | 30 | BULK-78aaa96e |
| 18720 | Bulk Product c899cfa3 | Home & Garden | $80.92 | 298 | ★ 3.7 | 14 | BULK-fe7720e9 |
| 18721 | Bulk Product 130da241 | Clothing | $755.55 | 158 | ★ 2.9 | 0 | BULK-a09d0fd4 |
| 18722 | Bulk Product ae2a60f5 | Toys & Games | $111.30 | 259 | ★ 0.0 | 12 | BULK-cb145e77 |
| 18723 | Bulk Product 7ac001fe | Sports & Outdoors | $696.19 | 271 | ★ 4.7 | 49 | BULK-789f0471 |
| 18724 | Bulk Product a1f8378c | Books | $289.47 | 164 | ★ 3.6 | 24 | BULK-93cebc15 |
| 18725 | Bulk Product e76db9c5 | Electronics | $902.73 | 261 | ★ 0.9 | 55 | BULK-6b0b9869 |
| 18726 | Bulk Product fbeb6f39 | Books | $222.82 | 56 | ★ 0.5 | 78 | BULK-50f402d0 |
| 18727 | Bulk Product 4cb07245 | Home & Garden | $705.31 | 406 | ★ 4.6 | 9 | BULK-a24141d1 |
| 18728 | Bulk Product 38c10f08 | Toys & Games | $958.62 | 126 | ★ 4.2 | 7 | BULK-0a225c78 |
| 18729 | Bulk Product 463195cd | Sports & Outdoors | $421.03 | 91 | ★ 0.7 | 30 | BULK-f123cd83 |
| 18730 | Bulk Product 8be76812 | Home & Garden | $774.89 | 437 | ★ 3.6 | 18 | BULK-f17bcb7c |
| 18731 | Bulk Product 3a18d15f | Electronics | $27.09 | 341 | ★ 0.9 | 1 | BULK-76b1f17e |
| 18732 | Bulk Product 32df7164 | Electronics | $827.74 | 334 | ★ 0.4 | 40 | BULK-35dae299 |
| 18733 | Bulk Product 091d56f1 | Clothing | $93.09 | 66 | ★ 2.5 | 42 | BULK-9bd9213b |
| 18734 | Bulk Product dd94dd70 | Sports & Outdoors | $912.41 | 232 | ★ 0.3 | 39 | BULK-18f5b2b9 |
// 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
};
}