Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4820 | Ultra Automotive Product Plus | Automotive | $455.98 | 360 | ★ 4.3 | 23 | SKU-004820 |
| 4821 | Economy Automotive Product Lite | Automotive | $180.33 | 481 | ★ 2.5 | 821 | SKU-004821 |
| 4822 | Pro Health & Beauty Product Max | Health & Beauty | $55.64 | 155 | ★ 1.2 | 514 | SKU-004822 |
| 4823 | Standard Sports & Outdoors Product Mini | Sports & Outdoors | $313.48 | 192 | ★ 3.0 | 813 | SKU-004823 |
| 4824 | Pro Books Product Lite | Books | $414.04 | 5 | ★ 1.3 | 629 | SKU-004824 |
| 4825 | Pro Automotive Product Classic | Automotive | $182.29 | 202 | ★ 2.8 | 767 | SKU-004825 |
| 4826 | Elite Toys & Games Product Special Edition | Toys & Games | $116.20 | 358 | ★ 2.1 | 613 | SKU-004826 |
| 4827 | Economy Home & Garden Product Plus | Home & Garden | $11.54 | 448 | ★ 3.7 | 535 | SKU-004827 |
| 4828 | Ultra Office Supplies Product Classic | Office Supplies | $414.76 | 478 | ★ 4.3 | 475 | SKU-004828 |
| 4829 | Professional Home & Garden Product Plus | Home & Garden | $51.07 | 46 | ★ 4.1 | 621 | SKU-004829 |
| 4830 | Elite Office Supplies Product Plus | Office Supplies | $997.56 | 206 | ★ 2.2 | 141 | SKU-004830 |
| 4831 | Pro Sports & Outdoors Product Pro | Sports & Outdoors | $92.43 | 90 | ★ 4.2 | 198 | SKU-004831 |
| 4832 | Premium Automotive Product Max | Automotive | $471.69 | 5 | ★ 1.2 | 863 | SKU-004832 |
| 4833 | Deluxe Office Supplies Product Advanced | Office Supplies | $119.55 | 384 | ★ 3.0 | 658 | SKU-004833 |
| 4834 | Economy Electronics Product Mini | Electronics | $253.81 | 20 | ★ 2.9 | 430 | SKU-004834 |
| 4835 | Mega Electronics Product Pro | Electronics | $973.19 | 29 | ★ 1.9 | 465 | SKU-004835 |
| 4836 | Economy Automotive Product Max | Automotive | $693.02 | 485 | ★ 3.0 | 469 | SKU-004836 |
| 4837 | Professional Automotive Product Pro | Automotive | $437.66 | 371 | ★ 1.3 | 790 | SKU-004837 |
| 4838 | Ultra Books Product Classic | Books | $375.19 | 166 | ★ 2.9 | 236 | SKU-004838 |
| 4839 | Mega Electronics Product Special Edition | Electronics | $434.21 | 178 | ★ 4.4 | 487 | SKU-004839 |
| 4840 | Economy Electronics Product Classic | Electronics | $470.66 | 189 | ★ 2.0 | 333 | SKU-004840 |
| 4841 | Super Home & Garden Product 2024 | Home & Garden | $593.10 | 10 | ★ 4.8 | 687 | SKU-004841 |
| 4842 | Elite Automotive Product Special Edition | Automotive | $366.89 | 255 | ★ 4.0 | 899 | SKU-004842 |
| 4843 | Mega Health & Beauty Product Plus | Health & Beauty | $93.56 | 78 | ★ 2.0 | 706 | SKU-004843 |
| 4844 | Pro Clothing Product Lite | Clothing | $224.07 | 453 | ★ 1.6 | 771 | SKU-004844 |
// 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
};
}