Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1563 | Professional Electronics Product Plus | Electronics | $875.87 | 94 | ★ 2.9 | 105 | SKU-001563 |
| 1564 | Elite Office Supplies Product Lite | Office Supplies | $975.38 | 151 | ★ 4.5 | 402 | SKU-001564 |
| 1566 | Pro Health & Beauty Product Advanced | Health & Beauty | $121.47 | 160 | ★ 1.7 | 453 | SKU-001566 |
| 1567 | Professional Office Supplies Product Pro | Office Supplies | $868.49 | 465 | ★ 4.3 | 810 | SKU-001567 |
| 1568 | Deluxe Automotive Product Plus | Automotive | $338.43 | 182 | ★ 2.5 | 915 | SKU-001568 |
| 1569 | Ultra Office Supplies Product 2024 | Office Supplies | $109.95 | 86 | ★ 3.9 | 803 | SKU-001569 |
| 1570 | Mega Clothing Product Lite | Clothing | $800.22 | 241 | ★ 4.9 | 699 | SKU-001570 |
| 1571 | Standard Home & Garden Product Max | Home & Garden | $276.01 | 145 | ★ 2.5 | 330 | SKU-001571 |
| 1572 | Standard Office Supplies Product 2024 | Office Supplies | $41.91 | 130 | ★ 2.3 | 810 | SKU-001572 |
| 1573 | Pro Automotive Product Lite | Automotive | $498.35 | 327 | ★ 1.1 | 700 | SKU-001573 |
| 1575 | Pro Office Supplies Product Classic | Office Supplies | $606.07 | 435 | ★ 4.1 | 968 | SKU-001575 |
| 1576 | Ultra Health & Beauty Product XL | Health & Beauty | $148.27 | 432 | ★ 3.3 | 70 | SKU-001576 |
| 1577 | Mega Clothing Product Lite | Clothing | $425.93 | 248 | ★ 3.3 | 879 | SKU-001577 |
| 1578 | Ultra Health & Beauty Product XL | Health & Beauty | $756.39 | 400 | ★ 3.7 | 75 | SKU-001578 |
| 1579 | Standard Clothing Product XL | Clothing | $186.57 | 173 | ★ 2.8 | 554 | SKU-001579 |
| 1581 | Premium Electronics Product Mini | Electronics | $807.79 | 387 | ★ 1.7 | 744 | SKU-001581 |
| 1582 | Standard Toys & Games Product 2024 | Toys & Games | $520.44 | 379 | ★ 1.3 | 822 | SKU-001582 |
| 1583 | Standard Health & Beauty Product 2024 | Health & Beauty | $245.59 | 481 | ★ 3.3 | 610 | SKU-001583 |
| 1584 | Pro Health & Beauty Product Mini | Health & Beauty | $958.86 | 400 | ★ 2.9 | 323 | SKU-001584 |
| 1585 | Standard Food & Grocery Product Lite | Food & Grocery | $455.55 | 439 | ★ 1.7 | 520 | SKU-001585 |
| 1586 | Standard Books Product Mini | Books | $929.25 | 357 | ★ 3.0 | 612 | SKU-001586 |
| 1587 | Professional Sports & Outdoors Product Classic | Sports & Outdoors | $336.15 | 150 | ★ 2.6 | 124 | SKU-001587 |
| 1588 | Premium Home & Garden Product Classic | Home & Garden | $286.23 | 167 | ★ 3.1 | 143 | SKU-001588 |
| 1589 | Elite Health & Beauty Product Lite | Health & Beauty | $121.36 | 477 | ★ 2.3 | 878 | SKU-001589 |
| 1590 | Premium Food & Grocery Product Max | Food & Grocery | $591.38 | 376 | ★ 1.9 | 740 | SKU-001590 |
// 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
};
}