Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1730 | Super Sports & Outdoors Product Advanced | Sports & Outdoors | $943.01 | 476 | ★ 3.0 | 482 | SKU-001730 |
| 1731 | Deluxe Sports & Outdoors Product Pro | Sports & Outdoors | $179.67 | 450 | ★ 4.6 | 323 | SKU-001731 |
| 1732 | Economy Health & Beauty Product Special Edition | Health & Beauty | $730.53 | 455 | ★ 4.6 | 320 | SKU-001732 |
| 1733 | Premium Books Product Advanced | Books | $449.95 | 462 | ★ 3.2 | 930 | SKU-001733 |
| 1734 | Pro Books Product 2024 | Books | $398.69 | 103 | ★ 5.0 | 363 | SKU-001734 |
| 1735 | Premium Office Supplies Product Special Edition | Office Supplies | $193.96 | 177 | ★ 2.2 | 296 | SKU-001735 |
| 1737 | Deluxe Electronics Product 2024 | Electronics | $201.58 | 215 | ★ 4.4 | 814 | SKU-001737 |
| 1738 | Deluxe Automotive Product Classic | Automotive | $575.10 | 73 | ★ 1.7 | 303 | SKU-001738 |
| 1740 | Economy Health & Beauty Product Mini | Health & Beauty | $425.10 | 395 | ★ 2.9 | 896 | SKU-001740 |
| 1741 | Premium Food & Grocery Product Pro | Food & Grocery | $933.74 | 85 | ★ 3.8 | 652 | SKU-001741 |
| 1742 | Standard Office Supplies Product Advanced | Office Supplies | $289.75 | 89 | ★ 2.2 | 630 | SKU-001742 |
| 1743 | Standard Automotive Product Mini | Automotive | $766.99 | 300 | ★ 3.6 | 310 | SKU-001743 |
| 1744 | Professional Office Supplies Product Classic | Office Supplies | $449.43 | 427 | ★ 2.3 | 212 | SKU-001744 |
| 1745 | Premium Home & Garden Product Mini | Home & Garden | $170.28 | 304 | ★ 2.6 | 206 | SKU-001745 |
| 1746 | Standard Office Supplies Product Plus | Office Supplies | $219.22 | 391 | ★ 3.7 | 304 | SKU-001746 |
| 1747 | Professional Automotive Product Lite | Automotive | $778.06 | 154 | ★ 2.0 | 723 | SKU-001747 |
| 1748 | Mega Electronics Product Pro | Electronics | $529.99 | 311 | ★ 2.8 | 434 | SKU-001748 |
| 1750 | Deluxe Clothing Product Max | Clothing | $849.44 | 17 | ★ 2.9 | 833 | SKU-001750 |
| 1751 | Ultra Sports & Outdoors Product Pro | Sports & Outdoors | $367.92 | 1 | ★ 4.8 | 159 | SKU-001751 |
| 1752 | Super Clothing Product Plus | Clothing | $82.72 | 385 | ★ 4.3 | 969 | SKU-001752 |
| 1753 | Elite Food & Grocery Product XL | Food & Grocery | $477.63 | 308 | ★ 1.7 | 768 | SKU-001753 |
| 1754 | Premium Food & Grocery Product Advanced | Food & Grocery | $540.23 | 160 | ★ 2.0 | 646 | SKU-001754 |
| 1755 | Mega Toys & Games Product Mini | Toys & Games | $611.51 | 210 | ★ 3.8 | 261 | SKU-001755 |
| 1756 | Mega Toys & Games Product Max | Toys & Games | $704.54 | 63 | ★ 3.7 | 315 | SKU-001756 |
| 1757 | Elite Automotive Product Lite | Automotive | $183.49 | 13 | ★ 3.1 | 248 | SKU-001757 |
// 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
};
}