Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8810 | Bulk Product dcaa9a00 | Books | $42.31 | 378 | ★ 5.0 | 62 | BULK-99a8df9d |
| 8811 | Bulk Product a913d5f6 | Sports & Outdoors | $653.61 | 438 | ★ 0.2 | 86 | BULK-d61f6f85 |
| 8812 | Bulk Product 3c7283c4 | Home & Garden | $256.90 | 390 | ★ 2.6 | 26 | BULK-66e35fff |
| 8813 | Bulk Product 971a3e65 | Sports & Outdoors | $985.85 | 421 | ★ 0.7 | 55 | BULK-0e824783 |
| 8814 | Bulk Product 1e19505f | Toys & Games | $38.76 | 138 | ★ 3.6 | 46 | BULK-913f7996 |
| 8815 | Bulk Product 918d1e5a | Sports & Outdoors | $305.09 | 328 | ★ 0.6 | 61 | BULK-12f79e2b |
| 8816 | Bulk Product c65a982f | Electronics | $225.36 | 336 | ★ 4.4 | 19 | BULK-63c4ccf8 |
| 8817 | Bulk Product fb55ad6f | Electronics | $564.17 | 187 | ★ 2.7 | 72 | BULK-8b3758a5 |
| 8818 | Bulk Product c1ed7018 | Electronics | $616.18 | 389 | ★ 3.5 | 71 | BULK-f10a686e |
| 8819 | Bulk Product a0d1e702 | Clothing | $263.60 | 188 | ★ 3.6 | 41 | BULK-e90677f8 |
| 8820 | Bulk Product b7178f34 | Home & Garden | $216.78 | 475 | ★ 1.8 | 81 | BULK-7392384d |
| 8821 | Bulk Product 39d18193 | Home & Garden | $988.63 | 72 | ★ 4.9 | 65 | BULK-10383c29 |
| 8822 | Bulk Product a9c42406 | Toys & Games | $626.18 | 141 | ★ 3.4 | 86 | BULK-5c9e8a30 |
| 8823 | Bulk Product 9d53b951 | Clothing | $42.96 | 112 | ★ 1.9 | 58 | BULK-9cf57a66 |
| 8824 | Bulk Product 810df834 | Electronics | $549.65 | 87 | ★ 4.7 | 50 | BULK-cc83387f |
| 8825 | Bulk Product 728d5d05 | Home & Garden | $802.56 | 399 | ★ 1.8 | 32 | BULK-f6684b86 |
| 8826 | Bulk Product 7493ceca | Sports & Outdoors | $404.43 | 298 | ★ 4.2 | 5 | BULK-86a91477 |
| 8827 | Bulk Product 91803117 | Electronics | $263.97 | 153 | ★ 3.3 | 48 | BULK-4c251b38 |
| 8828 | Bulk Product e9b5c5a2 | Electronics | $284.68 | 48 | ★ 3.3 | 68 | BULK-471fbd78 |
| 8829 | Bulk Product e8a206ba | Clothing | $682.69 | 374 | ★ 0.7 | 5 | BULK-faf03308 |
| 8830 | Bulk Product 2f1d2634 | Clothing | $376.09 | 462 | ★ 0.6 | 0 | BULK-7d69fe60 |
| 8831 | Bulk Product ee5240d0 | Electronics | $933.47 | 272 | ★ 3.4 | 94 | BULK-3b10b8b4 |
| 8832 | Bulk Product 8a7e994d | Home & Garden | $731.25 | 42 | ★ 1.2 | 17 | BULK-108f264e |
| 8833 | Bulk Product fdad0be9 | Clothing | $845.51 | 14 | ★ 0.7 | 54 | BULK-60260a10 |
| 8834 | Bulk Product 178f76fb | Sports & Outdoors | $573.25 | 465 | ★ 0.6 | 25 | BULK-7b7367a0 |
// 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
};
}