Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 22835 | Bulk Product df7534b7 | Sports & Outdoors | $856.05 | 241 | ★ 0.8 | 58 | BULK-19c97d50 |
| 22836 | Bulk Product d94753c5 | Electronics | $641.37 | 323 | ★ 2.8 | 30 | BULK-82c11062 |
| 22837 | Bulk Product 1a2cff0e | Sports & Outdoors | $917.17 | 415 | ★ 3.1 | 91 | BULK-4b648f40 |
| 22838 | Bulk Product e8f26c47 | Clothing | $120.08 | 40 | ★ 2.4 | 17 | BULK-2d486e1d |
| 22839 | Bulk Product 0d349734 | Toys & Games | $175.72 | 329 | ★ 2.0 | 23 | BULK-22c60015 |
| 22840 | Bulk Product e6097907 | Sports & Outdoors | $521.96 | 472 | ★ 3.6 | 30 | BULK-d0979364 |
| 22841 | Bulk Product c68c8fb4 | Electronics | $389.43 | 382 | ★ 0.7 | 1 | BULK-6a13ae0c |
| 22842 | Bulk Product 7988b50e | Electronics | $711.24 | 26 | ★ 1.8 | 88 | BULK-5d3acc34 |
| 22843 | Bulk Product 17d40a4a | Home & Garden | $177.31 | 268 | ★ 0.6 | 10 | BULK-3112c27a |
| 22844 | Bulk Product a48c5ccf | Toys & Games | $181.28 | 415 | ★ 1.5 | 69 | BULK-4ba130f7 |
| 22845 | Bulk Product fd85a2b5 | Sports & Outdoors | $71.12 | 92 | ★ 1.4 | 98 | BULK-5c6a67e3 |
| 22846 | Bulk Product 4c984a7c | Clothing | $658.22 | 433 | ★ 1.8 | 57 | BULK-bdbf0865 |
| 22847 | Bulk Product 154133b5 | Electronics | $677.92 | 197 | ★ 0.5 | 30 | BULK-12a074e3 |
| 22848 | Bulk Product abf93a05 | Electronics | $282.46 | 96 | ★ 1.6 | 9 | BULK-8e7d76e3 |
| 22849 | Bulk Product 66e33c13 | Books | $242.64 | 436 | ★ 2.1 | 8 | BULK-1c123d9d |
| 22850 | Bulk Product 867e1afb | Toys & Games | $573.02 | 322 | ★ 3.2 | 85 | BULK-cb07ec14 |
| 22851 | Bulk Product dfaed327 | Electronics | $431.96 | 175 | ★ 2.6 | 74 | BULK-2d18cf9d |
| 22852 | Bulk Product 49830541 | Clothing | $282.73 | 93 | ★ 2.0 | 56 | BULK-98e3f378 |
| 22853 | Bulk Product 92da39cd | Clothing | $571.87 | 459 | ★ 4.0 | 40 | BULK-3d3fca57 |
| 22854 | Bulk Product e513d2cd | Electronics | $466.16 | 375 | ★ 2.4 | 45 | BULK-955d848d |
| 22855 | Bulk Product 31b9c98c | Home & Garden | $452.63 | 303 | ★ 0.1 | 74 | BULK-e33ae38e |
| 22856 | Bulk Product cb00d940 | Electronics | $290.70 | 451 | ★ 2.3 | 38 | BULK-258a9009 |
| 22857 | Bulk Product 3534bfa0 | Clothing | $64.37 | 142 | ★ 0.7 | 3 | BULK-4b44c911 |
| 22858 | Bulk Product 62e2a37c | Toys & Games | $995.74 | 172 | ★ 1.8 | 42 | BULK-c42a5302 |
| 22859 | Bulk Product 7b3ae66b | Home & Garden | $551.45 | 3 | ★ 4.7 | 69 | BULK-6ea49916 |
// 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
};
}