Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 7735 | Bulk Product 273ecc1c | Electronics | $125.37 | 229 | ★ 4.5 | 44 | BULK-db8ee66c |
| 7736 | Bulk Product 5659d52f | Home & Garden | $475.26 | 126 | ★ 1.8 | 40 | BULK-c543bf0d |
| 7737 | Bulk Product b382f899 | Books | $740.35 | 475 | ★ 4.1 | 49 | BULK-cca447de |
| 7738 | Bulk Product f139c1a3 | Home & Garden | $372.91 | 274 | ★ 0.2 | 86 | BULK-46a8f5c4 |
| 7739 | Bulk Product 0cbedcce | Electronics | $696.01 | 421 | ★ 4.7 | 40 | BULK-7fddcc96 |
| 7740 | Bulk Product 2193c6f3 | Home & Garden | $609.07 | 346 | ★ 3.5 | 84 | BULK-9295474e |
| 7741 | Bulk Product c25afd9d | Home & Garden | $476.05 | 14 | ★ 4.5 | 37 | BULK-388b524c |
| 7742 | Bulk Product e909abe7 | Clothing | $955.20 | 228 | ★ 1.9 | 97 | BULK-592df791 |
| 7743 | Bulk Product 141cbbd3 | Clothing | $238.15 | 413 | ★ 2.5 | 84 | BULK-04e2fffa |
| 7744 | Bulk Product cefaddd4 | Clothing | $157.98 | 396 | ★ 3.5 | 59 | BULK-e0cd5c1f |
| 7745 | Bulk Product d4bbe9a9 | Clothing | $552.82 | 289 | ★ 4.2 | 96 | BULK-3d51a596 |
| 7746 | Bulk Product 9fe405c5 | Toys & Games | $504.80 | 355 | ★ 3.7 | 94 | BULK-52723c56 |
| 7747 | Bulk Product 637ee628 | Clothing | $874.37 | 202 | ★ 3.4 | 53 | BULK-bc1bc161 |
| 7748 | Bulk Product 91289789 | Clothing | $452.78 | 347 | ★ 2.8 | 35 | BULK-20eb1d8e |
| 7749 | Bulk Product ee7a7f13 | Sports & Outdoors | $73.77 | 460 | ★ 0.4 | 63 | BULK-e470a031 |
| 7750 | Bulk Product 9b9e1c18 | Electronics | $640.30 | 160 | ★ 3.1 | 30 | BULK-b5e4bb75 |
| 7751 | Bulk Product f32a1c00 | Clothing | $19.00 | 325 | ★ 3.6 | 29 | BULK-085d24f8 |
| 7752 | Bulk Product 48c1f5f0 | Sports & Outdoors | $30.45 | 198 | ★ 1.0 | 46 | BULK-c59752db |
| 7753 | Bulk Product dccb6038 | Sports & Outdoors | $956.67 | 484 | ★ 2.8 | 4 | BULK-4e56e7c2 |
| 7754 | Bulk Product 52a7454a | Clothing | $491.90 | 167 | ★ 2.3 | 87 | BULK-cea886b4 |
| 7755 | Bulk Product ff953699 | Electronics | $516.30 | 39 | ★ 3.3 | 79 | BULK-f3fb96dc |
| 7756 | Bulk Product 812ec1b0 | Sports & Outdoors | $106.12 | 37 | ★ 0.5 | 34 | BULK-d558d35d |
| 7757 | Bulk Product f999fe94 | Books | $875.19 | 427 | ★ 1.6 | 29 | BULK-69a4c03a |
| 7758 | Bulk Product 4012ef4d | Toys & Games | $606.87 | 254 | ★ 0.7 | 49 | BULK-5b83c8de |
| 7759 | Bulk Product 4fdf4efe | Electronics | $853.04 | 109 | ★ 1.6 | 73 | BULK-df403c71 |
// 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
};
}