Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2477 | Ultra Home & Garden Product 2024 | Home & Garden | $368.16 | 433 | ★ 1.2 | 880 | SKU-002477 |
| 2478 | Premium Home & Garden Product Pro | Home & Garden | $928.64 | 138 | ★ 1.0 | 740 | SKU-002478 |
| 2479 | Pro Home & Garden Product Max | Home & Garden | $437.66 | 479 | ★ 1.4 | 73 | SKU-002479 |
| 2480 | Mega Books Product Classic | Books | $496.24 | 339 | ★ 1.7 | 783 | SKU-002480 |
| 2481 | Pro Automotive Product Mini | Automotive | $456.50 | 414 | ★ 2.5 | 599 | SKU-002481 |
| 2482 | Pro Food & Grocery Product Mini | Food & Grocery | $650.73 | 185 | ★ 3.8 | 100 | SKU-002482 |
| 2483 | Super Home & Garden Product Lite | Home & Garden | $214.20 | 135 | ★ 3.9 | 571 | SKU-002483 |
| 2484 | Professional Home & Garden Product Pro | Home & Garden | $961.32 | 91 | ★ 4.3 | 850 | SKU-002484 |
| 2485 | Pro Sports & Outdoors Product Advanced | Sports & Outdoors | $896.88 | 271 | ★ 1.6 | 731 | SKU-002485 |
| 2486 | Standard Health & Beauty Product XL | Health & Beauty | $471.92 | 37 | ★ 4.2 | 8 | SKU-002486 |
| 2487 | Super Food & Grocery Product Pro | Food & Grocery | $243.29 | 310 | ★ 1.9 | 583 | SKU-002487 |
| 2488 | Economy Food & Grocery Product Mini | Food & Grocery | $70.42 | 393 | ★ 2.7 | 517 | SKU-002488 |
| 2489 | Deluxe Sports & Outdoors Product XL | Sports & Outdoors | $957.03 | 201 | ★ 3.0 | 318 | SKU-002489 |
| 2490 | Economy Office Supplies Product Pro | Office Supplies | $73.35 | 57 | ★ 3.8 | 516 | SKU-002490 |
| 2491 | Ultra Automotive Product 2024 | Automotive | $579.27 | 145 | ★ 2.3 | 642 | SKU-002491 |
| 2492 | Elite Electronics Product Max | Electronics | $116.78 | 395 | ★ 4.2 | 360 | SKU-002492 |
| 2493 | Professional Automotive Product Pro | Automotive | $472.66 | 174 | ★ 3.4 | 906 | SKU-002493 |
| 2494 | Pro Sports & Outdoors Product Plus | Sports & Outdoors | $984.87 | 232 | ★ 1.6 | 192 | SKU-002494 |
| 2495 | Economy Home & Garden Product Lite | Home & Garden | $85.03 | 91 | ★ 3.5 | 176 | SKU-002495 |
| 2497 | Professional Food & Grocery Product 2024 | Food & Grocery | $707.48 | 119 | ★ 4.8 | 4 | SKU-002497 |
| 2498 | Premium Books Product 2024 | Books | $569.63 | 97 | ★ 4.2 | 588 | SKU-002498 |
| 2499 | Super Home & Garden Product Classic | Home & Garden | $404.05 | 126 | ★ 3.3 | 237 | SKU-002499 |
| 2500 | Pro Electronics Product XL | Electronics | $507.51 | 53 | ★ 2.4 | 719 | SKU-002500 |
| 2501 | Pro Food & Grocery Product Pro | Food & Grocery | $684.42 | 345 | ★ 4.5 | 282 | SKU-002501 |
| 2502 | Premium Toys & Games Product Advanced | Toys & Games | $810.60 | 272 | ★ 1.4 | 377 | SKU-002502 |
// 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
};
}