Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1394 | Professional Clothing Product Advanced | Clothing | $937.73 | 481 | ★ 2.2 | 12 | SKU-001394 |
| 1395 | Ultra Books Product Max | Books | $318.70 | 125 | ★ 4.6 | 166 | SKU-001395 |
| 1396 | Elite Toys & Games Product Pro | Toys & Games | $760.21 | 289 | ★ 4.7 | 207 | SKU-001396 |
| 1397 | Professional Home & Garden Product Special Edition | Home & Garden | $892.70 | 173 | ★ 4.9 | 592 | SKU-001397 |
| 1398 | Professional Electronics Product Max | Electronics | $836.52 | 408 | ★ 3.0 | 270 | SKU-001398 |
| 1399 | Elite Food & Grocery Product Mini | Food & Grocery | $648.49 | 339 | ★ 1.0 | 37 | SKU-001399 |
| 1400 | Pro Toys & Games Product Advanced | Toys & Games | $581.29 | 162 | ★ 2.6 | 724 | SKU-001400 |
| 1401 | Ultra Sports & Outdoors Product Plus | Sports & Outdoors | $221.71 | 101 | ★ 1.4 | 684 | SKU-001401 |
| 1402 | Premium Automotive Product Advanced | Automotive | $459.69 | 281 | ★ 5.0 | 359 | SKU-001402 |
| 1403 | Economy Office Supplies Product Mini | Office Supplies | $445.45 | 285 | ★ 2.5 | 387 | SKU-001403 |
| 1404 | Premium Home & Garden Product Lite | Home & Garden | $718.34 | 152 | ★ 3.9 | 1 | SKU-001404 |
| 1405 | Ultra Clothing Product Mini | Clothing | $489.62 | 404 | ★ 2.5 | 646 | SKU-001405 |
| 1406 | Professional Books Product Lite | Books | $29.52 | 404 | ★ 2.7 | 747 | SKU-001406 |
| 1407 | Super Home & Garden Product Pro | Home & Garden | $615.14 | 176 | ★ 4.0 | 762 | SKU-001407 |
| 1408 | Standard Sports & Outdoors Product XL | Sports & Outdoors | $30.37 | 212 | ★ 4.2 | 477 | SKU-001408 |
| 1409 | Elite Health & Beauty Product Classic | Health & Beauty | $222.98 | 23 | ★ 2.7 | 502 | SKU-001409 |
| 1410 | Professional Toys & Games Product Lite | Toys & Games | $955.27 | 156 | ★ 2.1 | 3 | SKU-001410 |
| 1411 | Standard Sports & Outdoors Product XL | Sports & Outdoors | $572.85 | 288 | ★ 3.3 | 949 | SKU-001411 |
| 1412 | Deluxe Automotive Product Pro | Automotive | $769.53 | 230 | ★ 2.0 | 303 | SKU-001412 |
| 1413 | Premium Office Supplies Product Max | Office Supplies | $339.82 | 294 | ★ 4.2 | 653 | SKU-001413 |
| 1414 | Standard Home & Garden Product XL | Home & Garden | $109.16 | 82 | ★ 4.6 | 189 | SKU-001414 |
| 1415 | Mega Health & Beauty Product Advanced | Health & Beauty | $845.02 | 235 | ★ 3.3 | 571 | SKU-001415 |
| 1416 | Deluxe Health & Beauty Product 2024 | Health & Beauty | $859.57 | 124 | ★ 4.0 | 271 | SKU-001416 |
| 1417 | Ultra Office Supplies Product Mini | Office Supplies | $566.48 | 108 | ★ 3.6 | 505 | SKU-001417 |
| 1418 | Economy Office Supplies Product Classic | Office Supplies | $559.24 | 172 | ★ 1.4 | 796 | SKU-001418 |
// 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
};
}