Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1618 | Standard Toys & Games Product Classic | Toys & Games | $19.79 | 429 | ★ 1.8 | 575 | SKU-001618 |
| 1619 | Super Automotive Product Mini | Automotive | $159.38 | 86 | ★ 3.6 | 781 | SKU-001619 |
| 1620 | Super Electronics Product Advanced | Electronics | $766.30 | 396 | ★ 5.0 | 14 | SKU-001620 |
| 1621 | Professional Clothing Product Advanced | Clothing | $467.83 | 171 | ★ 2.2 | 144 | SKU-001621 |
| 1622 | Deluxe Toys & Games Product Plus | Toys & Games | $420.91 | 441 | ★ 4.2 | 316 | SKU-001622 |
| 1624 | Elite Home & Garden Product Lite | Home & Garden | $361.43 | 123 | ★ 1.9 | 81 | SKU-001624 |
| 1625 | Ultra Toys & Games Product Classic | Toys & Games | $184.84 | 172 | ★ 2.0 | 938 | SKU-001625 |
| 1626 | Elite Office Supplies Product Lite | Office Supplies | $999.35 | 352 | ★ 1.8 | 509 | SKU-001626 |
| 1627 | Professional Toys & Games Product Mini | Toys & Games | $491.17 | 160 | ★ 3.9 | 66 | SKU-001627 |
| 1629 | Elite Sports & Outdoors Product 2024 | Sports & Outdoors | $335.47 | 289 | ★ 2.7 | 114 | SKU-001629 |
| 1630 | Mega Food & Grocery Product Advanced | Food & Grocery | $688.70 | 187 | ★ 2.5 | 759 | SKU-001630 |
| 1631 | Premium Health & Beauty Product Lite | Health & Beauty | $495.55 | 247 | ★ 4.4 | 367 | SKU-001631 |
| 1632 | Mega Books Product Plus | Books | $848.61 | 178 | ★ 4.8 | 720 | SKU-001632 |
| 1633 | Premium Food & Grocery Product XL | Food & Grocery | $369.02 | 72 | ★ 3.5 | 580 | SKU-001633 |
| 1634 | Elite Automotive Product Plus | Automotive | $451.92 | 349 | ★ 3.1 | 323 | SKU-001634 |
| 1635 | Mega Office Supplies Product Mini | Office Supplies | $415.32 | 4 | ★ 4.8 | 820 | SKU-001635 |
| 1636 | Deluxe Automotive Product Classic | Automotive | $602.73 | 366 | ★ 2.3 | 691 | SKU-001636 |
| 1637 | Deluxe Books Product Special Edition | Books | $273.13 | 251 | ★ 3.9 | 191 | SKU-001637 |
| 1638 | Professional Electronics Product Advanced | Electronics | $561.77 | 182 | ★ 1.9 | 146 | SKU-001638 |
| 1639 | Super Toys & Games Product Pro | Toys & Games | $334.32 | 311 | ★ 2.2 | 279 | SKU-001639 |
| 1640 | Economy Food & Grocery Product XL | Food & Grocery | $314.31 | 8 | ★ 4.5 | 377 | SKU-001640 |
| 1641 | Ultra Electronics Product Classic | Electronics | $196.85 | 48 | ★ 4.2 | 301 | SKU-001641 |
| 1642 | Standard Food & Grocery Product Advanced | Food & Grocery | $74.48 | 0 | ★ 3.7 | 243 | SKU-001642 |
| 1643 | Economy Food & Grocery Product Plus | Food & Grocery | $486.97 | 105 | ★ 4.3 | 257 | SKU-001643 |
| 1644 | Elite Clothing Product Lite | Clothing | $616.91 | 150 | ★ 3.7 | 826 | SKU-001644 |
// 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
};
}