Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3816 | Ultra Office Supplies Product Mini | Office Supplies | $240.84 | 39 | ★ 2.4 | 645 | SKU-003816 |
| 3817 | Super Office Supplies Product Special Edition | Office Supplies | $811.55 | 257 | ★ 2.4 | 8 | SKU-003817 |
| 3819 | Premium Electronics Product Max | Electronics | $293.35 | 484 | ★ 3.6 | 315 | SKU-003819 |
| 3820 | Standard Health & Beauty Product Special Edition | Health & Beauty | $167.18 | 214 | ★ 1.7 | 555 | SKU-003820 |
| 3821 | Deluxe Sports & Outdoors Product Lite | Sports & Outdoors | $30.03 | 420 | ★ 2.7 | 295 | SKU-003821 |
| 3822 | Super Electronics Product Lite | Electronics | $728.74 | 9 | ★ 3.3 | 954 | SKU-003822 |
| 3823 | Ultra Books Product Advanced | Books | $199.17 | 451 | ★ 4.7 | 906 | SKU-003823 |
| 3824 | Economy Toys & Games Product Plus | Toys & Games | $789.81 | 114 | ★ 3.6 | 713 | SKU-003824 |
| 3825 | Ultra Electronics Product Mini | Electronics | $759.19 | 220 | ★ 4.9 | 137 | SKU-003825 |
| 3826 | Premium Home & Garden Product Mini | Home & Garden | $490.50 | 421 | ★ 4.3 | 847 | SKU-003826 |
| 3827 | Economy Health & Beauty Product Max | Health & Beauty | $954.06 | 108 | ★ 2.0 | 353 | SKU-003827 |
| 3828 | Professional Electronics Product Lite | Electronics | $574.35 | 365 | ★ 2.0 | 751 | SKU-003828 |
| 3829 | Deluxe Food & Grocery Product Advanced | Food & Grocery | $789.21 | 31 | ★ 1.0 | 60 | SKU-003829 |
| 3830 | Pro Home & Garden Product Max | Home & Garden | $241.78 | 97 | ★ 2.9 | 547 | SKU-003830 |
| 3831 | Ultra Toys & Games Product Mini | Toys & Games | $664.50 | 99 | ★ 4.2 | 139 | SKU-003831 |
| 3832 | Super Food & Grocery Product 2024 | Food & Grocery | $190.96 | 111 | ★ 2.3 | 654 | SKU-003832 |
| 3833 | Pro Office Supplies Product Classic | Office Supplies | $949.05 | 394 | ★ 3.3 | 789 | SKU-003833 |
| 3834 | Elite Books Product Classic | Books | $885.34 | 240 | ★ 1.1 | 595 | SKU-003834 |
| 3835 | Pro Sports & Outdoors Product Plus | Sports & Outdoors | $295.85 | 231 | ★ 2.2 | 376 | SKU-003835 |
| 3836 | Ultra Food & Grocery Product Plus | Food & Grocery | $883.70 | 358 | ★ 2.9 | 653 | SKU-003836 |
| 3837 | Mega Sports & Outdoors Product Special Edition | Sports & Outdoors | $266.01 | 225 | ★ 4.5 | 857 | SKU-003837 |
| 3838 | Deluxe Sports & Outdoors Product Plus | Sports & Outdoors | $718.18 | 358 | ★ 2.1 | 186 | SKU-003838 |
| 3839 | Economy Health & Beauty Product Classic | Health & Beauty | $342.29 | 369 | ★ 4.8 | 385 | SKU-003839 |
| 3840 | Ultra Electronics Product Mini | Electronics | $286.21 | 339 | ★ 2.9 | 365 | SKU-003840 |
| 3842 | Elite Health & Beauty Product Classic | Health & Beauty | $838.89 | 431 | ★ 4.2 | 743 | SKU-003842 |
// 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
};
}