Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 588 | Pro Automotive Product XL | Automotive | $423.90 | 294 | ★ 2.8 | 410 | SKU-000588 |
| 589 | Super Automotive Product 2024 | Automotive | $892.79 | 378 | ★ 1.4 | 702 | SKU-000589 |
| 590 | Deluxe Health & Beauty Product Classic | Health & Beauty | $312.40 | 43 | ★ 3.1 | 657 | SKU-000590 |
| 591 | Economy Sports & Outdoors Product Pro | Sports & Outdoors | $827.17 | 449 | ★ 4.2 | 347 | SKU-000591 |
| 592 | Pro Automotive Product 2024 | Automotive | $473.74 | 77 | ★ 3.2 | 650 | SKU-000592 |
| 593 | Pro Home & Garden Product Pro | Home & Garden | $786.59 | 117 | ★ 2.3 | 490 | SKU-000593 |
| 594 | Pro Toys & Games Product Mini | Toys & Games | $237.75 | 319 | ★ 2.8 | 5 | SKU-000594 |
| 595 | Super Clothing Product 2024 | Clothing | $429.34 | 431 | ★ 2.1 | 10 | SKU-000595 |
| 596 | Super Office Supplies Product Plus | Office Supplies | $195.53 | 415 | ★ 4.1 | 56 | SKU-000596 |
| 597 | Deluxe Food & Grocery Product Lite | Food & Grocery | $742.12 | 400 | ★ 2.9 | 5 | SKU-000597 |
| 598 | Standard Sports & Outdoors Product Special Edition | Sports & Outdoors | $224.62 | 470 | ★ 3.0 | 436 | SKU-000598 |
| 599 | Premium Health & Beauty Product Mini | Health & Beauty | $884.66 | 307 | ★ 1.3 | 659 | SKU-000599 |
| 600 | Professional Electronics Product Pro | Electronics | $420.31 | 67 | ★ 4.6 | 8 | SKU-000600 |
| 601 | Premium Sports & Outdoors Product XL | Sports & Outdoors | $947.61 | 77 | ★ 2.7 | 617 | SKU-000601 |
| 602 | Deluxe Electronics Product Mini | Electronics | $710.63 | 221 | ★ 2.8 | 324 | SKU-000602 |
| 603 | Economy Home & Garden Product Lite | Home & Garden | $361.62 | 464 | ★ 2.8 | 727 | SKU-000603 |
| 605 | Premium Clothing Product XL | Clothing | $102.28 | 269 | ★ 4.6 | 119 | SKU-000605 |
| 606 | Premium Sports & Outdoors Product Classic | Sports & Outdoors | $961.94 | 278 | ★ 3.6 | 260 | SKU-000606 |
| 607 | Pro Food & Grocery Product Mini | Food & Grocery | $625.26 | 419 | ★ 1.3 | 16 | SKU-000607 |
| 608 | Super Food & Grocery Product Special Edition | Food & Grocery | $99.52 | 388 | ★ 3.8 | 857 | SKU-000608 |
| 609 | Pro Home & Garden Product Plus | Home & Garden | $749.81 | 403 | ★ 5.0 | 134 | SKU-000609 |
| 610 | Premium Health & Beauty Product Lite | Health & Beauty | $465.61 | 388 | ★ 2.0 | 368 | SKU-000610 |
| 611 | Standard Home & Garden Product Plus | Home & Garden | $946.30 | 456 | ★ 3.5 | 295 | SKU-000611 |
| 612 | Elite Automotive Product Classic | Automotive | $702.50 | 377 | ★ 2.2 | 107 | SKU-000612 |
| 613 | Deluxe Automotive Product XL | Automotive | $107.71 | 449 | ★ 3.2 | 208 | SKU-000613 |
// 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
};
}