Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1475 | Super Books Product Pro | Books | $357.90 | 173 | ★ 3.0 | 130 | SKU-001475 |
| 1476 | Super Food & Grocery Product 2024 | Food & Grocery | $775.41 | 318 | ★ 2.4 | 593 | SKU-001476 |
| 1477 | Ultra Food & Grocery Product Mini | Food & Grocery | $115.87 | 44 | ★ 2.6 | 161 | SKU-001477 |
| 1478 | Standard Clothing Product Mini | Clothing | $344.26 | 166 | ★ 4.6 | 496 | SKU-001478 |
| 1479 | Ultra Office Supplies Product XL | Office Supplies | $569.54 | 354 | ★ 1.2 | 777 | SKU-001479 |
| 1480 | Deluxe Sports & Outdoors Product Mini | Sports & Outdoors | $558.31 | 18 | ★ 2.9 | 634 | SKU-001480 |
| 1482 | Super Health & Beauty Product Classic | Health & Beauty | $342.73 | 23 | ★ 4.0 | 61 | SKU-001482 |
| 1483 | Economy Sports & Outdoors Product Lite | Sports & Outdoors | $588.00 | 258 | ★ 2.9 | 332 | SKU-001483 |
| 1484 | Deluxe Electronics Product Special Edition | Electronics | $155.70 | 102 | ★ 3.8 | 777 | SKU-001484 |
| 1485 | Super Office Supplies Product Special Edition | Office Supplies | $749.33 | 307 | ★ 2.7 | 556 | SKU-001485 |
| 1487 | Standard Sports & Outdoors Product Classic | Sports & Outdoors | $405.14 | 267 | ★ 4.7 | 552 | SKU-001487 |
| 1488 | Pro Clothing Product Plus | Clothing | $406.26 | 462 | ★ 4.3 | 634 | SKU-001488 |
| 1489 | Elite Food & Grocery Product Classic | Food & Grocery | $161.25 | 52 | ★ 4.5 | 489 | SKU-001489 |
| 1490 | Professional Health & Beauty Product Pro | Health & Beauty | $15.26 | 253 | ★ 1.8 | 39 | SKU-001490 |
| 1491 | Deluxe Home & Garden Product Pro | Home & Garden | $721.22 | 252 | ★ 2.3 | 503 | SKU-001491 |
| 1493 | Pro Books Product Special Edition | Books | $461.38 | 440 | ★ 4.9 | 515 | SKU-001493 |
| 1495 | Ultra Automotive Product Plus | Automotive | $861.37 | 158 | ★ 3.2 | 550 | SKU-001495 |
| 1496 | Super Food & Grocery Product Advanced | Food & Grocery | $730.90 | 427 | ★ 3.7 | 947 | SKU-001496 |
| 1497 | Premium Electronics Product Plus | Electronics | $765.20 | 397 | ★ 1.3 | 245 | SKU-001497 |
| 1498 | Super Health & Beauty Product Max | Health & Beauty | $477.86 | 77 | ★ 4.9 | 807 | SKU-001498 |
| 1499 | Standard Toys & Games Product Plus | Toys & Games | $105.70 | 73 | ★ 1.8 | 316 | SKU-001499 |
| 1501 | Pro Books Product XL | Books | $650.03 | 263 | ★ 1.3 | 238 | SKU-001501 |
| 1503 | Ultra Food & Grocery Product Pro | Food & Grocery | $857.80 | 488 | ★ 4.4 | 338 | SKU-001503 |
| 1504 | Mega Health & Beauty Product Mini | Health & Beauty | $423.19 | 406 | ★ 4.1 | 811 | SKU-001504 |
| 1505 | Pro Sports & Outdoors Product Classic | Sports & Outdoors | $845.99 | 72 | ★ 1.7 | 257 | SKU-001505 |
// 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
};
}