Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1786 | Standard Sports & Outdoors Product Classic | Sports & Outdoors | $326.97 | 58 | ★ 5.0 | 487 | SKU-001786 |
| 1787 | Economy Food & Grocery Product 2024 | Food & Grocery | $760.45 | 66 | ★ 4.4 | 87 | SKU-001787 |
| 1788 | Standard Automotive Product Advanced | Automotive | $631.44 | 357 | ★ 2.7 | 308 | SKU-001788 |
| 1789 | Elite Clothing Product Mini | Clothing | $776.10 | 10 | ★ 1.4 | 333 | SKU-001789 |
| 1790 | Pro Clothing Product Plus | Clothing | $860.20 | 30 | ★ 3.5 | 25 | SKU-001790 |
| 1791 | Economy Books Product Mini | Books | $534.00 | 193 | ★ 3.9 | 626 | SKU-001791 |
| 1792 | Premium Clothing Product Max | Clothing | $921.12 | 84 | ★ 1.7 | 527 | SKU-001792 |
| 1793 | Elite Toys & Games Product Lite | Toys & Games | $645.61 | 377 | ★ 3.0 | 154 | SKU-001793 |
| 1794 | Elite Books Product Special Edition | Books | $634.47 | 309 | ★ 2.1 | 438 | SKU-001794 |
| 1796 | Super Food & Grocery Product 2024 | Food & Grocery | $603.63 | 300 | ★ 3.2 | 566 | SKU-001796 |
| 1797 | Economy Food & Grocery Product Classic | Food & Grocery | $710.59 | 91 | ★ 4.7 | 9 | SKU-001797 |
| 1798 | Ultra Health & Beauty Product Special Edition | Health & Beauty | $382.33 | 454 | ★ 2.4 | 12 | SKU-001798 |
| 1799 | Super Toys & Games Product Pro | Toys & Games | $397.84 | 20 | ★ 3.0 | 757 | SKU-001799 |
| 1800 | Super Food & Grocery Product Plus | Food & Grocery | $220.55 | 237 | ★ 3.7 | 728 | SKU-001800 |
| 1801 | Elite Health & Beauty Product Advanced | Health & Beauty | $139.67 | 344 | ★ 4.5 | 674 | SKU-001801 |
| 1802 | Ultra Toys & Games Product Classic | Toys & Games | $652.83 | 151 | ★ 3.5 | 831 | SKU-001802 |
| 1803 | Deluxe Electronics Product Plus | Electronics | $145.47 | 237 | ★ 4.8 | 501 | SKU-001803 |
| 1804 | Economy Food & Grocery Product Classic | Food & Grocery | $168.22 | 255 | ★ 2.0 | 897 | SKU-001804 |
| 1805 | Economy Toys & Games Product Special Edition | Toys & Games | $252.37 | 160 | ★ 1.4 | 35 | SKU-001805 |
| 1806 | Pro Home & Garden Product Mini | Home & Garden | $987.72 | 333 | ★ 1.4 | 528 | SKU-001806 |
| 1807 | Premium Food & Grocery Product Advanced | Food & Grocery | $706.62 | 223 | ★ 4.6 | 243 | SKU-001807 |
| 1808 | Mega Toys & Games Product Pro | Toys & Games | $323.80 | 345 | ★ 2.9 | 718 | SKU-001808 |
| 1810 | Super Sports & Outdoors Product Classic | Sports & Outdoors | $896.04 | 134 | ★ 1.3 | 880 | SKU-001810 |
| 1811 | Deluxe Electronics Product XL | Electronics | $89.57 | 205 | ★ 4.5 | 2 | SKU-001811 |
| 1812 | Premium Food & Grocery Product Plus | Food & Grocery | $715.86 | 488 | ★ 4.7 | 768 | SKU-001812 |
// 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
};
}