Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 15685 | Bulk Product 22d5b870 | Books | $559.89 | 84 | ★ 1.0 | 87 | BULK-bf686f23 |
| 15686 | Bulk Product 2de17d58 | Electronics | $60.32 | 176 | ★ 3.4 | 73 | BULK-528b3f0f |
| 15687 | Bulk Product 4aca3aca | Sports & Outdoors | $536.04 | 285 | ★ 1.3 | 95 | BULK-0fc99b7b |
| 15688 | Bulk Product 90a1f06c | Electronics | $817.91 | 242 | ★ 2.1 | 57 | BULK-a3cf5c05 |
| 15689 | Bulk Product 7ca36d15 | Books | $673.90 | 233 | ★ 3.4 | 49 | BULK-f9296ad5 |
| 15690 | Bulk Product 5ba23e46 | Electronics | $115.97 | 330 | ★ 3.5 | 73 | BULK-2dd94892 |
| 15691 | Bulk Product 03b33a06 | Toys & Games | $704.49 | 256 | ★ 1.6 | 54 | BULK-3f64ddd2 |
| 15692 | Bulk Product 880c6437 | Sports & Outdoors | $646.20 | 428 | ★ 3.6 | 37 | BULK-7ed6502b |
| 15693 | Bulk Product bd1d1d39 | Toys & Games | $334.11 | 23 | ★ 3.5 | 36 | BULK-033666ba |
| 15694 | Bulk Product c4d2a802 | Electronics | $645.85 | 138 | ★ 1.6 | 61 | BULK-1366f51c |
| 15695 | Bulk Product 5e1cc01e | Sports & Outdoors | $881.24 | 115 | ★ 4.7 | 53 | BULK-55cac8d9 |
| 15696 | Bulk Product 59327eed | Clothing | $240.98 | 370 | ★ 1.4 | 3 | BULK-db23b162 |
| 15697 | Bulk Product 13ee29bd | Clothing | $42.78 | 174 | ★ 4.6 | 33 | BULK-219dd691 |
| 15698 | Bulk Product 39fd6557 | Electronics | $803.70 | 478 | ★ 0.8 | 96 | BULK-de2963e7 |
| 15699 | Bulk Product cd708c62 | Sports & Outdoors | $994.67 | 407 | ★ 1.5 | 73 | BULK-428038e8 |
| 15700 | Bulk Product 17b8c86d | Clothing | $46.35 | 137 | ★ 0.7 | 12 | BULK-d02c30d9 |
| 15701 | Bulk Product 358b35ec | Clothing | $261.68 | 456 | ★ 1.8 | 94 | BULK-7870e316 |
| 15702 | Bulk Product e1015365 | Clothing | $45.14 | 60 | ★ 1.1 | 59 | BULK-52a76b07 |
| 15703 | Bulk Product cec2f658 | Clothing | $981.56 | 257 | ★ 3.2 | 85 | BULK-3d21daae |
| 15704 | Bulk Product b474b85b | Toys & Games | $771.83 | 67 | ★ 2.8 | 37 | BULK-b80e0ca8 |
| 15705 | Bulk Product 9a6840f3 | Toys & Games | $822.40 | 316 | ★ 1.1 | 31 | BULK-12b37f4b |
| 15706 | Bulk Product 21f80f21 | Toys & Games | $901.63 | 298 | ★ 4.5 | 97 | BULK-f61eee52 |
| 15707 | Bulk Product d3074994 | Sports & Outdoors | $77.69 | 470 | ★ 3.8 | 37 | BULK-e8779f5d |
| 15708 | Bulk Product 834a2de7 | Books | $167.25 | 251 | ★ 2.4 | 51 | BULK-3f900493 |
| 15709 | Bulk Product 8fdd13b9 | Sports & Outdoors | $640.84 | 429 | ★ 1.2 | 11 | BULK-92dc7086 |
// 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
};
}