Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3843 | Economy Home & Garden Product Pro | Home & Garden | $867.85 | 34 | ★ 3.2 | 881 | SKU-003843 |
| 3844 | Economy Food & Grocery Product Advanced | Food & Grocery | $857.09 | 64 | ★ 3.4 | 383 | SKU-003844 |
| 3846 | Mega Automotive Product Special Edition | Automotive | $748.36 | 343 | ★ 4.8 | 211 | SKU-003846 |
| 3848 | Economy Health & Beauty Product Classic | Health & Beauty | $55.77 | 308 | ★ 3.8 | 145 | SKU-003848 |
| 3849 | Pro Office Supplies Product Lite | Office Supplies | $853.46 | 410 | ★ 3.9 | 369 | SKU-003849 |
| 3850 | Ultra Home & Garden Product Max | Home & Garden | $587.80 | 499 | ★ 3.3 | 176 | SKU-003850 |
| 3851 | Standard Automotive Product Lite | Automotive | $488.78 | 413 | ★ 3.7 | 420 | SKU-003851 |
| 3852 | Professional Home & Garden Product Classic | Home & Garden | $904.08 | 142 | ★ 3.8 | 300 | SKU-003852 |
| 3853 | Standard Automotive Product Max | Automotive | $691.47 | 280 | ★ 3.7 | 28 | SKU-003853 |
| 3854 | Super Home & Garden Product Pro | Home & Garden | $477.20 | 41 | ★ 2.5 | 281 | SKU-003854 |
| 3855 | Mega Electronics Product Special Edition | Electronics | $185.69 | 304 | ★ 3.3 | 473 | SKU-003855 |
| 3856 | Pro Automotive Product 2024 | Automotive | $534.27 | 236 | ★ 4.2 | 868 | SKU-003856 |
| 3858 | Pro Home & Garden Product 2024 | Home & Garden | $108.74 | 283 | ★ 1.3 | 190 | SKU-003858 |
| 3859 | Super Office Supplies Product Max | Office Supplies | $371.24 | 376 | ★ 1.6 | 470 | SKU-003859 |
| 3860 | Mega Health & Beauty Product Special Edition | Health & Beauty | $474.55 | 395 | ★ 1.7 | 314 | SKU-003860 |
| 3861 | Pro Clothing Product Lite | Clothing | $905.38 | 99 | ★ 4.2 | 99 | SKU-003861 |
| 3862 | Ultra Food & Grocery Product Mini | Food & Grocery | $946.32 | 495 | ★ 3.7 | 432 | SKU-003862 |
| 3863 | Professional Automotive Product Max | Automotive | $23.35 | 144 | ★ 2.2 | 662 | SKU-003863 |
| 3866 | Premium Sports & Outdoors Product XL | Sports & Outdoors | $693.95 | 400 | ★ 1.8 | 558 | SKU-003866 |
| 3867 | Economy Automotive Product Pro | Automotive | $738.11 | 449 | ★ 4.0 | 898 | SKU-003867 |
| 3868 | Deluxe Electronics Product Special Edition | Electronics | $387.33 | 268 | ★ 4.7 | 808 | SKU-003868 |
| 3869 | Standard Office Supplies Product Lite | Office Supplies | $865.28 | 161 | ★ 3.9 | 873 | SKU-003869 |
| 3870 | Ultra Automotive Product Plus | Automotive | $445.40 | 246 | ★ 1.0 | 592 | SKU-003870 |
| 3872 | Standard Home & Garden Product Max | Home & Garden | $370.46 | 455 | ★ 3.5 | 224 | SKU-003872 |
| 3873 | Standard Office Supplies Product Special Edition | Office Supplies | $355.61 | 156 | ★ 2.5 | 269 | SKU-003873 |
// 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
};
}