Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 10760 | Bulk Product 90f4736d | Books | $554.15 | 464 | ★ 0.9 | 43 | BULK-f9c906d9 |
| 10761 | Bulk Product aa64984e | Sports & Outdoors | $230.40 | 399 | ★ 4.6 | 85 | BULK-2ba79d95 |
| 10762 | Bulk Product b13f0276 | Clothing | $363.60 | 307 | ★ 1.4 | 8 | BULK-93120f49 |
| 10763 | Bulk Product 59ddde26 | Toys & Games | $174.04 | 181 | ★ 4.9 | 37 | BULK-708f47d0 |
| 10764 | Bulk Product 679a3a42 | Books | $16.95 | 65 | ★ 1.6 | 23 | BULK-964d045d |
| 10765 | Bulk Product 7a933dda | Toys & Games | $957.88 | 179 | ★ 2.1 | 22 | BULK-ac664f39 |
| 10766 | Bulk Product 9ec45527 | Home & Garden | $369.51 | 254 | ★ 1.7 | 30 | BULK-8b64e7d8 |
| 10767 | Bulk Product 9ae05da6 | Clothing | $555.13 | 90 | ★ 0.4 | 38 | BULK-1f56da69 |
| 10768 | Bulk Product 17eaf214 | Toys & Games | $998.21 | 151 | ★ 0.1 | 78 | BULK-b05f2c30 |
| 10769 | Bulk Product 07546d85 | Toys & Games | $556.25 | 194 | ★ 0.9 | 37 | BULK-62b1e674 |
| 10770 | Bulk Product ecf0f5a7 | Home & Garden | $44.18 | 280 | ★ 3.0 | 28 | BULK-8326db77 |
| 10771 | Bulk Product 475971de | Clothing | $674.21 | 264 | ★ 4.1 | 46 | BULK-d9cb6614 |
| 10772 | Bulk Product a2b8fa79 | Sports & Outdoors | $460.01 | 352 | ★ 2.6 | 9 | BULK-de1daf78 |
| 10773 | Bulk Product 582d58cd | Books | $365.92 | 97 | ★ 1.6 | 94 | BULK-469448a6 |
| 10774 | Bulk Product 269e2843 | Books | $470.48 | 2 | ★ 4.1 | 88 | BULK-7c2e1765 |
| 10775 | Bulk Product 027b1adf | Books | $616.94 | 494 | ★ 4.4 | 22 | BULK-0ef3a949 |
| 10776 | Bulk Product f2d55712 | Electronics | $307.21 | 499 | ★ 1.2 | 14 | BULK-bf3b71a9 |
| 10777 | Bulk Product 059b50e6 | Sports & Outdoors | $137.88 | 424 | ★ 4.3 | 65 | BULK-104be443 |
| 10778 | Bulk Product 672e349f | Books | $687.65 | 200 | ★ 3.9 | 3 | BULK-dc3a7947 |
| 10779 | Bulk Product 7e2571a0 | Home & Garden | $730.01 | 259 | ★ 2.0 | 54 | BULK-8d74f27f |
| 10780 | Bulk Product 596c7eea | Toys & Games | $788.50 | 98 | ★ 2.0 | 61 | BULK-d16e1065 |
| 10781 | Bulk Product 175076af | Toys & Games | $115.13 | 309 | ★ 4.6 | 61 | BULK-9aa597d0 |
| 10782 | Bulk Product 20b1bc68 | Toys & Games | $430.77 | 222 | ★ 2.6 | 35 | BULK-3b597b6f |
| 10783 | Bulk Product fbc260f7 | Toys & Games | $85.20 | 375 | ★ 4.8 | 74 | BULK-6ccdaef2 |
| 10784 | Bulk Product c65c6dfb | Electronics | $171.45 | 299 | ★ 1.4 | 55 | BULK-8060070f |
// 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
};
}