Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 22810 | Bulk Product 23dd811b | Home & Garden | $603.12 | 287 | ★ 1.4 | 74 | BULK-7d7999a9 |
| 22811 | Bulk Product 6e188926 | Electronics | $670.51 | 419 | ★ 5.0 | 78 | BULK-b2618f50 |
| 22812 | Bulk Product 774bbfc3 | Clothing | $893.91 | 373 | ★ 1.8 | 22 | BULK-0337a9c1 |
| 22813 | Bulk Product a1e1f4df | Books | $116.90 | 199 | ★ 2.0 | 42 | BULK-e8bce11f |
| 22814 | Bulk Product 1796e91e | Toys & Games | $848.07 | 55 | ★ 1.1 | 15 | BULK-154b5582 |
| 22815 | Bulk Product 81810454 | Electronics | $926.24 | 424 | ★ 2.3 | 9 | BULK-faf5b01e |
| 22816 | Bulk Product 3cbf44ab | Clothing | $437.26 | 36 | ★ 0.2 | 36 | BULK-cf4d8306 |
| 22817 | Bulk Product 1eccbf60 | Toys & Games | $648.55 | 181 | ★ 0.5 | 45 | BULK-f27a1e2e |
| 22818 | Bulk Product d4701e4e | Home & Garden | $975.93 | 27 | ★ 3.3 | 98 | BULK-206a0f22 |
| 22819 | Bulk Product 13284db4 | Electronics | $85.54 | 372 | ★ 4.5 | 25 | BULK-c3b2c22f |
| 22820 | Bulk Product fd980643 | Home & Garden | $233.77 | 348 | ★ 1.0 | 29 | BULK-68ec7ec4 |
| 22821 | Bulk Product 51dccc08 | Electronics | $57.27 | 50 | ★ 4.4 | 15 | BULK-fa9663ae |
| 22822 | Bulk Product 74fdcab3 | Home & Garden | $866.66 | 229 | ★ 4.0 | 42 | BULK-5df255bc |
| 22823 | Bulk Product c7b871a1 | Clothing | $170.89 | 107 | ★ 2.7 | 67 | BULK-7e57baf7 |
| 22824 | Bulk Product 73d7f442 | Toys & Games | $684.78 | 190 | ★ 4.8 | 56 | BULK-50c51fce |
| 22825 | Bulk Product ac22f685 | Electronics | $413.05 | 110 | ★ 1.7 | 96 | BULK-df1e59bb |
| 22826 | Bulk Product 2a8ec819 | Sports & Outdoors | $779.33 | 391 | ★ 2.7 | 28 | BULK-ad44441a |
| 22827 | Bulk Product 1b930cc7 | Clothing | $833.43 | 247 | ★ 1.7 | 12 | BULK-d53b5854 |
| 22828 | Bulk Product 24b0749c | Books | $95.11 | 405 | ★ 3.4 | 1 | BULK-71cf60d3 |
| 22829 | Bulk Product 9531ab2f | Clothing | $144.50 | 211 | ★ 2.0 | 99 | BULK-128d8b15 |
| 22830 | Bulk Product 3a5978ea | Sports & Outdoors | $349.07 | 384 | ★ 4.3 | 72 | BULK-4dae7114 |
| 22831 | Bulk Product 25571995 | Books | $68.99 | 380 | ★ 3.9 | 58 | BULK-c114b4ea |
| 22832 | Bulk Product c983bb19 | Toys & Games | $988.35 | 396 | ★ 0.7 | 7 | BULK-0aa86e44 |
| 22833 | Bulk Product 878fc26b | Sports & Outdoors | $614.00 | 216 | ★ 1.1 | 10 | BULK-d7204134 |
| 22834 | Bulk Product f625bc43 | Books | $986.85 | 409 | ★ 4.3 | 63 | BULK-1896e791 |
// 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
};
}