Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17260 | Bulk Product a154c81b | Toys & Games | $304.60 | 55 | ★ 1.8 | 90 | BULK-c4406ee1 |
| 17261 | Bulk Product 7d552f42 | Electronics | $474.41 | 124 | ★ 1.6 | 22 | BULK-a26a57c2 |
| 17262 | Bulk Product 174e0095 | Books | $17.96 | 168 | ★ 1.9 | 46 | BULK-a5b7e0d4 |
| 17263 | Bulk Product 004121d9 | Toys & Games | $863.41 | 285 | ★ 2.1 | 72 | BULK-00569627 |
| 17264 | Bulk Product 5ffdbac3 | Home & Garden | $229.60 | 467 | ★ 2.3 | 55 | BULK-90500e0a |
| 17265 | Bulk Product fdf8f5d7 | Sports & Outdoors | $607.91 | 68 | ★ 4.6 | 8 | BULK-0f82a208 |
| 17266 | Bulk Product 6e48c6c3 | Books | $808.80 | 216 | ★ 4.1 | 32 | BULK-ef76b771 |
| 17267 | Bulk Product 84d4e498 | Books | $188.57 | 26 | ★ 2.0 | 86 | BULK-22fbb0d7 |
| 17268 | Bulk Product b7998844 | Clothing | $26.84 | 220 | ★ 0.3 | 36 | BULK-47768165 |
| 17269 | Bulk Product 51fa0f61 | Books | $581.95 | 380 | ★ 4.6 | 71 | BULK-d3487ef6 |
| 17270 | Bulk Product 7d5de5a6 | Home & Garden | $246.69 | 158 | ★ 0.1 | 82 | BULK-e3084291 |
| 17271 | Bulk Product 6525056e | Sports & Outdoors | $925.97 | 248 | ★ 0.4 | 30 | BULK-9ef67db0 |
| 17272 | Bulk Product 0f2f7101 | Toys & Games | $310.38 | 165 | ★ 2.1 | 4 | BULK-fbcaeeac |
| 17273 | Bulk Product e0a70785 | Clothing | $984.44 | 346 | ★ 3.3 | 99 | BULK-bf3263d6 |
| 17274 | Bulk Product f2f51feb | Home & Garden | $725.16 | 4 | ★ 4.2 | 60 | BULK-248beb5b |
| 17275 | Bulk Product ce086aa8 | Toys & Games | $911.63 | 443 | ★ 0.1 | 29 | BULK-4eae1752 |
| 17276 | Bulk Product f5c15944 | Toys & Games | $354.19 | 155 | ★ 2.4 | 80 | BULK-9d6f48be |
| 17277 | Bulk Product 376003ec | Clothing | $332.70 | 403 | ★ 3.4 | 67 | BULK-c648a4bd |
| 17278 | Bulk Product 43c5a6f1 | Clothing | $266.46 | 401 | ★ 3.3 | 75 | BULK-071bd791 |
| 17279 | Bulk Product 700d4d20 | Sports & Outdoors | $219.17 | 498 | ★ 3.8 | 33 | BULK-afb69c41 |
| 17280 | Bulk Product be7f9e68 | Electronics | $225.96 | 489 | ★ 2.2 | 56 | BULK-e2d2fcfd |
| 17281 | Bulk Product ac78fc1a | Toys & Games | $275.40 | 389 | ★ 4.6 | 76 | BULK-856c17b8 |
| 17282 | Bulk Product 6003ef74 | Toys & Games | $937.12 | 416 | ★ 3.9 | 45 | BULK-401315d0 |
| 17283 | Bulk Product a10f7149 | Sports & Outdoors | $550.33 | 212 | ★ 1.0 | 48 | BULK-f72b524c |
| 17284 | Bulk Product 052f9df8 | Sports & Outdoors | $349.72 | 361 | ★ 4.1 | 62 | BULK-f2239117 |
// 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
};
}