Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 20810 | Bulk Product 0edca705 | Electronics | $26.28 | 45 | ★ 0.0 | 37 | BULK-17fcf24b |
| 20811 | Bulk Product 63a9e719 | Sports & Outdoors | $347.21 | 127 | ★ 2.7 | 19 | BULK-47d32f64 |
| 20812 | Bulk Product c9f09e9c | Toys & Games | $226.79 | 100 | ★ 3.3 | 77 | BULK-84dd560f |
| 20813 | Bulk Product 44ff3bf7 | Electronics | $270.26 | 141 | ★ 1.1 | 44 | BULK-0829185f |
| 20814 | Bulk Product 3fc56d24 | Sports & Outdoors | $987.96 | 236 | ★ 4.5 | 87 | BULK-3afdad75 |
| 20815 | Bulk Product de30e287 | Sports & Outdoors | $925.90 | 374 | ★ 1.3 | 21 | BULK-96c9932b |
| 20816 | Bulk Product fc916f0a | Toys & Games | $81.64 | 4 | ★ 1.1 | 72 | BULK-73a826a1 |
| 20817 | Bulk Product 149ad321 | Electronics | $24.43 | 488 | ★ 2.5 | 65 | BULK-effee056 |
| 20818 | Bulk Product 12dcd1b7 | Books | $346.48 | 140 | ★ 1.8 | 2 | BULK-1675bc19 |
| 20819 | Bulk Product 8fbf5f32 | Clothing | $349.72 | 466 | ★ 0.8 | 74 | BULK-9e306795 |
| 20820 | Bulk Product aee50a91 | Toys & Games | $152.39 | 195 | ★ 0.8 | 28 | BULK-1c997b49 |
| 20821 | Bulk Product d9c447d1 | Books | $112.96 | 467 | ★ 3.2 | 24 | BULK-61e316f5 |
| 20822 | Bulk Product fb8a22c4 | Toys & Games | $374.32 | 184 | ★ 1.5 | 19 | BULK-ccffbb1f |
| 20823 | Bulk Product 7592d7b7 | Books | $531.82 | 420 | ★ 3.4 | 30 | BULK-0bcbb832 |
| 20824 | Bulk Product c928d5b6 | Sports & Outdoors | $918.00 | 278 | ★ 4.0 | 14 | BULK-a794dcdb |
| 20825 | Bulk Product 1c921f8c | Electronics | $712.24 | 19 | ★ 3.4 | 86 | BULK-652e3a8c |
| 20826 | Bulk Product 2dfc2066 | Books | $935.67 | 137 | ★ 3.7 | 20 | BULK-8ad0499f |
| 20827 | Bulk Product c7c90a55 | Electronics | $13.64 | 318 | ★ 1.9 | 0 | BULK-6f5546be |
| 20828 | Bulk Product 33dffb4a | Books | $1,003.15 | 398 | ★ 0.3 | 20 | BULK-92bd4221 |
| 20829 | Bulk Product d38d5802 | Clothing | $459.55 | 38 | ★ 4.4 | 13 | BULK-8da6420d |
| 20830 | Bulk Product 38f13678 | Books | $584.11 | 463 | ★ 3.1 | 22 | BULK-4b7fd5ef |
| 20831 | Bulk Product c74f609a | Clothing | $34.11 | 120 | ★ 1.5 | 83 | BULK-9461e45d |
| 20832 | Bulk Product b433ed7d | Books | $420.80 | 285 | ★ 2.7 | 98 | BULK-66f9bbab |
| 20833 | Bulk Product ed170188 | Toys & Games | $50.14 | 158 | ★ 0.2 | 38 | BULK-dd5663ec |
| 20834 | Bulk Product a9a47a60 | Books | $280.55 | 328 | ★ 0.1 | 10 | BULK-9432a635 |
// 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
};
}