Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 14760 | Bulk Product 448e8ea2 | Home & Garden | $351.84 | 145 | ★ 2.8 | 93 | BULK-a1ede602 |
| 14761 | Bulk Product ca135a52 | Toys & Games | $247.42 | 347 | ★ 1.2 | 19 | BULK-ad4afd81 |
| 14762 | Bulk Product 61adee75 | Electronics | $309.82 | 281 | ★ 4.1 | 39 | BULK-918cce25 |
| 14763 | Bulk Product 4fd848e5 | Toys & Games | $829.69 | 387 | ★ 2.5 | 15 | BULK-4f1de3d6 |
| 14764 | Bulk Product 80f171db | Electronics | $840.33 | 187 | ★ 0.8 | 86 | BULK-ec1a23e5 |
| 14765 | Bulk Product e96b74a7 | Clothing | $536.64 | 376 | ★ 4.1 | 72 | BULK-f04d211f |
| 14766 | Bulk Product 2f90ce9e | Electronics | $82.03 | 454 | ★ 2.0 | 84 | BULK-0e841e20 |
| 14767 | Bulk Product b1a01126 | Home & Garden | $865.62 | 207 | ★ 2.5 | 59 | BULK-0a8438c3 |
| 14768 | Bulk Product f6c01e74 | Toys & Games | $982.88 | 453 | ★ 1.9 | 93 | BULK-f97b8093 |
| 14769 | Bulk Product fdc67c64 | Sports & Outdoors | $946.02 | 188 | ★ 1.3 | 8 | BULK-7efa7aac |
| 14770 | Bulk Product f3c63614 | Books | $945.36 | 199 | ★ 3.2 | 34 | BULK-66e22e51 |
| 14771 | Bulk Product 0711cc44 | Toys & Games | $476.03 | 180 | ★ 3.8 | 80 | BULK-db9ff105 |
| 14772 | Bulk Product 92d7b4ae | Sports & Outdoors | $233.37 | 71 | ★ 4.3 | 2 | BULK-17151c66 |
| 14773 | Bulk Product a50444d0 | Toys & Games | $599.00 | 48 | ★ 1.3 | 21 | BULK-06fd0d44 |
| 14774 | Bulk Product 2a104bb6 | Books | $448.66 | 178 | ★ 1.6 | 12 | BULK-b784be2e |
| 14775 | Bulk Product 20f28f02 | Electronics | $315.91 | 323 | ★ 3.6 | 68 | BULK-d1549c74 |
| 14776 | Bulk Product 2f04dff8 | Clothing | $55.76 | 61 | ★ 2.8 | 80 | BULK-e0c1d5a5 |
| 14777 | Bulk Product d1bc834b | Toys & Games | $985.90 | 129 | ★ 3.4 | 38 | BULK-6dc2516e |
| 14778 | Bulk Product b677109c | Clothing | $587.47 | 40 | ★ 2.0 | 96 | BULK-27993307 |
| 14779 | Bulk Product 0675b24b | Toys & Games | $374.89 | 489 | ★ 4.3 | 49 | BULK-736185ad |
| 14780 | Bulk Product 5198202a | Books | $306.08 | 402 | ★ 4.8 | 96 | BULK-e95a6dae |
| 14781 | Bulk Product 45ffeea9 | Toys & Games | $42.36 | 477 | ★ 2.3 | 5 | BULK-9344389e |
| 14782 | Bulk Product 418b0c4a | Electronics | $390.27 | 241 | ★ 1.6 | 44 | BULK-0d523bfb |
| 14783 | Bulk Product c803a452 | Sports & Outdoors | $263.77 | 210 | ★ 1.8 | 64 | BULK-0e9359ae |
| 14784 | Bulk Product 0fce73fd | Toys & Games | $961.62 | 374 | ★ 4.0 | 22 | BULK-a7d18cd7 |
// 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
};
}