Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3137 | Premium Sports & Outdoors Product Mini | Sports & Outdoors | $623.72 | 498 | ★ 2.2 | 532 | SKU-003137 |
| 3138 | Super Health & Beauty Product XL | Health & Beauty | $119.44 | 363 | ★ 1.8 | 51 | SKU-003138 |
| 3139 | Standard Food & Grocery Product Max | Food & Grocery | $328.28 | 428 | ★ 1.4 | 725 | SKU-003139 |
| 3140 | Elite Books Product XL | Books | $508.17 | 320 | ★ 4.1 | 572 | SKU-003140 |
| 3141 | Pro Home & Garden Product Max | Home & Garden | $545.09 | 245 | ★ 4.4 | 178 | SKU-003141 |
| 3142 | Pro Books Product Plus | Books | $872.00 | 195 | ★ 4.1 | 530 | SKU-003142 |
| 3143 | Economy Toys & Games Product Lite | Toys & Games | $236.86 | 325 | ★ 4.5 | 208 | SKU-003143 |
| 3144 | Mega Books Product Classic | Books | $892.53 | 174 | ★ 1.4 | 440 | SKU-003144 |
| 3145 | Economy Automotive Product 2024 | Automotive | $348.59 | 93 | ★ 1.5 | 569 | SKU-003145 |
| 3146 | Mega Office Supplies Product Advanced | Office Supplies | $267.68 | 173 | ★ 2.2 | 323 | SKU-003146 |
| 3147 | Deluxe Automotive Product Advanced | Automotive | $56.13 | 288 | ★ 2.3 | 552 | SKU-003147 |
| 3148 | Standard Toys & Games Product 2024 | Toys & Games | $366.75 | 52 | ★ 1.7 | 997 | SKU-003148 |
| 3149 | Super Clothing Product Max | Clothing | $356.19 | 393 | ★ 2.7 | 156 | SKU-003149 |
| 3150 | Economy Home & Garden Product Lite | Home & Garden | $16.92 | 212 | ★ 3.1 | 928 | SKU-003150 |
| 3151 | Elite Sports & Outdoors Product Special Edition | Sports & Outdoors | $827.54 | 276 | ★ 3.7 | 184 | SKU-003151 |
| 3152 | Ultra Toys & Games Product 2024 | Toys & Games | $66.89 | 491 | ★ 4.3 | 290 | SKU-003152 |
| 3154 | Economy Home & Garden Product Lite | Home & Garden | $756.12 | 432 | ★ 2.2 | 432 | SKU-003154 |
| 3155 | Deluxe Clothing Product Pro | Clothing | $964.45 | 320 | ★ 2.4 | 583 | SKU-003155 |
| 3156 | Economy Food & Grocery Product Max | Food & Grocery | $761.03 | 488 | ★ 3.7 | 623 | SKU-003156 |
| 3157 | Professional Books Product Pro | Books | $509.56 | 480 | ★ 4.8 | 407 | SKU-003157 |
| 3158 | Super Electronics Product Mini | Electronics | $561.67 | 266 | ★ 1.3 | 493 | SKU-003158 |
| 3159 | Economy Electronics Product Classic | Electronics | $316.20 | 444 | ★ 4.7 | 579 | SKU-003159 |
| 3160 | Ultra Electronics Product Special Edition | Electronics | $170.54 | 172 | ★ 2.7 | 852 | SKU-003160 |
| 3161 | Economy Health & Beauty Product Classic | Health & Beauty | $324.79 | 188 | ★ 4.1 | 762 | SKU-003161 |
| 3162 | Economy Clothing Product Lite | Clothing | $333.38 | 241 | ★ 3.3 | 624 | SKU-003162 |
// 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
};
}