Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1840 | Ultra Sports & Outdoors Product Classic | Sports & Outdoors | $43.53 | 339 | ★ 4.5 | 80 | SKU-001840 |
| 1841 | Super Home & Garden Product Lite | Home & Garden | $284.65 | 453 | ★ 1.2 | 141 | SKU-001841 |
| 1842 | Pro Home & Garden Product Pro | Home & Garden | $933.07 | 446 | ★ 4.6 | 179 | SKU-001842 |
| 1843 | Ultra Health & Beauty Product Pro | Health & Beauty | $435.40 | 18 | ★ 3.3 | 97 | SKU-001843 |
| 1844 | Pro Toys & Games Product XL | Toys & Games | $922.54 | 406 | ★ 4.8 | 15 | SKU-001844 |
| 1845 | Standard Sports & Outdoors Product 2024 | Sports & Outdoors | $929.45 | 246 | ★ 4.0 | 289 | SKU-001845 |
| 1846 | Professional Health & Beauty Product Lite | Health & Beauty | $438.06 | 250 | ★ 3.9 | 194 | SKU-001846 |
| 1847 | Premium Books Product Pro | Books | $989.39 | 89 | ★ 1.2 | 981 | SKU-001847 |
| 1848 | Pro Electronics Product Classic | Electronics | $723.33 | 320 | ★ 1.0 | 916 | SKU-001848 |
| 1849 | Deluxe Office Supplies Product Plus | Office Supplies | $410.82 | 333 | ★ 1.7 | 400 | SKU-001849 |
| 1850 | Standard Health & Beauty Product XL | Health & Beauty | $564.65 | 0 | ★ 3.0 | 797 | SKU-001850 |
| 1851 | Professional Clothing Product Advanced | Clothing | $293.89 | 279 | ★ 1.7 | 563 | SKU-001851 |
| 1852 | Pro Health & Beauty Product Plus | Health & Beauty | $216.90 | 307 | ★ 2.5 | 187 | SKU-001852 |
| 1853 | Standard Health & Beauty Product Classic | Health & Beauty | $108.23 | 211 | ★ 4.5 | 733 | SKU-001853 |
| 1854 | Economy Books Product Classic | Books | $234.14 | 484 | ★ 1.2 | 795 | SKU-001854 |
| 1855 | Pro Sports & Outdoors Product Max | Sports & Outdoors | $351.04 | 364 | ★ 3.0 | 884 | SKU-001855 |
| 1856 | Pro Home & Garden Product Pro | Home & Garden | $656.93 | 260 | ★ 1.6 | 365 | SKU-001856 |
| 1857 | Premium Toys & Games Product Mini | Toys & Games | $807.46 | 350 | ★ 4.4 | 374 | SKU-001857 |
| 1858 | Professional Clothing Product Pro | Clothing | $995.09 | 324 | ★ 2.8 | 921 | SKU-001858 |
| 1859 | Elite Home & Garden Product Advanced | Home & Garden | $198.79 | 481 | ★ 3.4 | 259 | SKU-001859 |
| 1860 | Economy Health & Beauty Product Classic | Health & Beauty | $49.89 | 157 | ★ 2.8 | 917 | SKU-001860 |
| 1861 | Standard Electronics Product Special Edition | Electronics | $350.98 | 92 | ★ 3.8 | 692 | SKU-001861 |
| 1862 | Elite Toys & Games Product Lite | Toys & Games | $163.53 | 246 | ★ 1.6 | 791 | SKU-001862 |
| 1863 | Premium Clothing Product Special Edition | Clothing | $787.33 | 444 | ★ 1.1 | 696 | SKU-001863 |
| 1864 | Super Office Supplies Product 2024 | Office Supplies | $149.15 | 135 | ★ 4.3 | 473 | SKU-001864 |
// 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
};
}