Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4535 | Elite Electronics Product Pro | Electronics | $939.77 | 80 | ★ 2.0 | 902 | SKU-004535 |
| 4537 | Standard Automotive Product Max | Automotive | $442.02 | 363 | ★ 3.6 | 254 | SKU-004537 |
| 4539 | Deluxe Books Product Mini | Books | $763.12 | 447 | ★ 3.2 | 139 | SKU-004539 |
| 4540 | Standard Automotive Product Mini | Automotive | $634.34 | 363 | ★ 4.3 | 617 | SKU-004540 |
| 4542 | Pro Sports & Outdoors Product XL | Sports & Outdoors | $972.27 | 176 | ★ 4.6 | 565 | SKU-004542 |
| 4543 | Ultra Toys & Games Product Classic | Toys & Games | $900.60 | 247 | ★ 3.0 | 560 | SKU-004543 |
| 4544 | Premium Health & Beauty Product 2024 | Health & Beauty | $775.39 | 91 | ★ 1.2 | 708 | SKU-004544 |
| 4545 | Deluxe Toys & Games Product Lite | Toys & Games | $754.57 | 462 | ★ 4.1 | 648 | SKU-004545 |
| 4546 | Mega Sports & Outdoors Product XL | Sports & Outdoors | $735.62 | 149 | ★ 2.8 | 576 | SKU-004546 |
| 4547 | Premium Sports & Outdoors Product Mini | Sports & Outdoors | $350.24 | 47 | ★ 3.5 | 879 | SKU-004547 |
| 4548 | Elite Clothing Product XL | Clothing | $770.18 | 163 | ★ 1.8 | 425 | SKU-004548 |
| 4549 | Ultra Toys & Games Product Advanced | Toys & Games | $182.62 | 438 | ★ 2.2 | 444 | SKU-004549 |
| 4550 | Super Automotive Product Lite | Automotive | $921.45 | 358 | ★ 2.9 | 237 | SKU-004550 |
| 4551 | Ultra Health & Beauty Product Advanced | Health & Beauty | $875.94 | 468 | ★ 4.1 | 831 | SKU-004551 |
| 4552 | Professional Home & Garden Product 2024 | Home & Garden | $249.85 | 390 | ★ 2.2 | 391 | SKU-004552 |
| 4553 | Professional Sports & Outdoors Product Lite | Sports & Outdoors | $397.24 | 318 | ★ 3.6 | 862 | SKU-004553 |
| 4554 | Economy Toys & Games Product Pro | Toys & Games | $295.02 | 271 | ★ 3.4 | 58 | SKU-004554 |
| 4555 | Super Food & Grocery Product Max | Food & Grocery | $548.30 | 16 | ★ 3.1 | 303 | SKU-004555 |
| 4556 | Premium Automotive Product Max | Automotive | $52.95 | 444 | ★ 4.3 | 684 | SKU-004556 |
| 4557 | Mega Electronics Product XL | Electronics | $436.63 | 490 | ★ 2.0 | 658 | SKU-004557 |
| 4559 | Ultra Home & Garden Product 2024 | Home & Garden | $44.52 | 192 | ★ 4.6 | 229 | SKU-004559 |
| 4561 | Standard Sports & Outdoors Product Mini | Sports & Outdoors | $734.71 | 339 | ★ 4.2 | 908 | SKU-004561 |
| 4562 | Economy Home & Garden Product XL | Home & Garden | $911.93 | 350 | ★ 1.5 | 374 | SKU-004562 |
| 4563 | Premium Books Product 2024 | Books | $775.99 | 13 | ★ 3.6 | 615 | SKU-004563 |
| 4564 | Economy Automotive Product Mini | Automotive | $52.90 | 228 | ★ 4.4 | 357 | SKU-004564 |
// 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
};
}