Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1097 | Economy Toys & Games Product Classic | Toys & Games | $847.62 | 338 | ★ 3.7 | 387 | SKU-001097 |
| 1098 | Super Clothing Product Lite | Clothing | $653.28 | 54 | ★ 4.8 | 898 | SKU-001098 |
| 1099 | Ultra Automotive Product Classic | Automotive | $756.19 | 139 | ★ 4.3 | 738 | SKU-001099 |
| 1100 | Super Food & Grocery Product XL | Food & Grocery | $403.13 | 61 | ★ 2.9 | 337 | SKU-001100 |
| 1101 | Standard Office Supplies Product Special Edition | Office Supplies | $612.03 | 79 | ★ 3.8 | 648 | SKU-001101 |
| 1102 | Standard Toys & Games Product Lite | Toys & Games | $558.76 | 135 | ★ 2.6 | 664 | SKU-001102 |
| 1103 | Ultra Automotive Product Pro | Automotive | $499.08 | 20 | ★ 4.8 | 383 | SKU-001103 |
| 1104 | Super Home & Garden Product Pro | Home & Garden | $780.91 | 362 | ★ 4.7 | 136 | SKU-001104 |
| 1105 | Deluxe Office Supplies Product Plus | Office Supplies | $966.37 | 425 | ★ 1.0 | 614 | SKU-001105 |
| 1106 | Economy Home & Garden Product Plus | Home & Garden | $178.79 | 480 | ★ 3.7 | 690 | SKU-001106 |
| 1108 | Elite Books Product 2024 | Books | $447.91 | 74 | ★ 3.9 | 480 | SKU-001108 |
| 1109 | Premium Clothing Product Special Edition | Clothing | $197.08 | 339 | ★ 4.7 | 505 | SKU-001109 |
| 1110 | Deluxe Electronics Product Pro | Electronics | $683.61 | 87 | ★ 4.8 | 320 | SKU-001110 |
| 1111 | Pro Clothing Product XL | Clothing | $680.94 | 194 | ★ 4.4 | 44 | SKU-001111 |
| 1112 | Elite Food & Grocery Product Lite | Food & Grocery | $831.54 | 374 | ★ 3.8 | 31 | SKU-001112 |
| 1115 | Super Books Product Max | Books | $931.87 | 326 | ★ 4.7 | 954 | SKU-001115 |
| 1116 | Deluxe Office Supplies Product Special Edition | Office Supplies | $700.17 | 133 | ★ 1.9 | 453 | SKU-001116 |
| 1118 | Economy Electronics Product Max | Electronics | $492.68 | 184 | ★ 3.8 | 932 | SKU-001118 |
| 1119 | Deluxe Food & Grocery Product 2024 | Food & Grocery | $471.44 | 127 | ★ 4.4 | 822 | SKU-001119 |
| 1121 | Premium Clothing Product Special Edition | Clothing | $350.45 | 351 | ★ 2.4 | 811 | SKU-001121 |
| 1122 | Elite Food & Grocery Product XL | Food & Grocery | $486.01 | 246 | ★ 4.1 | 172 | SKU-001122 |
| 1123 | Elite Health & Beauty Product Special Edition | Health & Beauty | $626.48 | 457 | ★ 4.5 | 193 | SKU-001123 |
| 1124 | Professional Health & Beauty Product Max | Health & Beauty | $106.42 | 36 | ★ 2.5 | 194 | SKU-001124 |
| 1125 | Super Food & Grocery Product Plus | Food & Grocery | $939.23 | 122 | ★ 3.0 | 299 | SKU-001125 |
| 1126 | Ultra Home & Garden Product Special Edition | Home & Garden | $160.25 | 211 | ★ 1.8 | 588 | SKU-001126 |
// 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
};
}