Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2670 | Ultra Home & Garden Product Mini | Home & Garden | $122.99 | 185 | ★ 1.2 | 295 | SKU-002670 |
| 2671 | Elite Office Supplies Product Mini | Office Supplies | $135.26 | 106 | ★ 4.0 | 968 | SKU-002671 |
| 2672 | Elite Automotive Product Plus | Automotive | $501.06 | 112 | ★ 3.3 | 161 | SKU-002672 |
| 2673 | Super Electronics Product Pro | Electronics | $559.77 | 6 | ★ 1.9 | 382 | SKU-002673 |
| 2674 | Elite Automotive Product Max | Automotive | $514.12 | 394 | ★ 3.7 | 645 | SKU-002674 |
| 2675 | Deluxe Automotive Product Max | Automotive | $535.65 | 206 | ★ 1.4 | 760 | SKU-002675 |
| 2676 | Super Health & Beauty Product Classic | Health & Beauty | $540.77 | 259 | ★ 3.1 | 418 | SKU-002676 |
| 2677 | Economy Food & Grocery Product Plus | Food & Grocery | $489.01 | 107 | ★ 3.5 | 993 | SKU-002677 |
| 2678 | Ultra Office Supplies Product Special Edition | Office Supplies | $47.63 | 49 | ★ 2.9 | 239 | SKU-002678 |
| 2679 | Ultra Toys & Games Product Special Edition | Toys & Games | $241.06 | 124 | ★ 1.2 | 407 | SKU-002679 |
| 2680 | Standard Toys & Games Product Advanced | Toys & Games | $697.23 | 474 | ★ 2.0 | 15 | SKU-002680 |
| 2682 | Deluxe Automotive Product Advanced | Automotive | $220.89 | 107 | ★ 4.0 | 317 | SKU-002682 |
| 2683 | Ultra Toys & Games Product 2024 | Toys & Games | $180.58 | 129 | ★ 4.5 | 581 | SKU-002683 |
| 2684 | Super Clothing Product Lite | Clothing | $463.10 | 400 | ★ 1.0 | 693 | SKU-002684 |
| 2685 | Professional Health & Beauty Product 2024 | Health & Beauty | $502.14 | 209 | ★ 2.9 | 104 | SKU-002685 |
| 2686 | Mega Automotive Product Pro | Automotive | $92.02 | 443 | ★ 3.3 | 363 | SKU-002686 |
| 2688 | Pro Home & Garden Product Classic | Home & Garden | $262.79 | 390 | ★ 1.8 | 581 | SKU-002688 |
| 2689 | Standard Electronics Product Advanced | Electronics | $881.56 | 161 | ★ 2.7 | 898 | SKU-002689 |
| 2690 | Standard Toys & Games Product Max | Toys & Games | $298.33 | 162 | ★ 3.3 | 556 | SKU-002690 |
| 2691 | Professional Sports & Outdoors Product Pro | Sports & Outdoors | $586.09 | 335 | ★ 1.2 | 563 | SKU-002691 |
| 2692 | Deluxe Sports & Outdoors Product Plus | Sports & Outdoors | $198.51 | 490 | ★ 1.1 | 859 | SKU-002692 |
| 2693 | Ultra Office Supplies Product Max | Office Supplies | $77.34 | 22 | ★ 3.0 | 477 | SKU-002693 |
| 2694 | Mega Health & Beauty Product Special Edition | Health & Beauty | $278.44 | 29 | ★ 3.2 | 17 | SKU-002694 |
| 2695 | Pro Health & Beauty Product Advanced | Health & Beauty | $391.22 | 193 | ★ 1.1 | 870 | SKU-002695 |
| 2696 | Mega Health & Beauty Product Lite | Health & Beauty | $508.43 | 2 | ★ 1.5 | 757 | SKU-002696 |
// 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
};
}