Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2807 | Deluxe Office Supplies Product Mini | Office Supplies | $212.32 | 344 | ★ 4.2 | 493 | SKU-002807 |
| 2808 | Economy Office Supplies Product Plus | Office Supplies | $802.97 | 111 | ★ 3.0 | 703 | SKU-002808 |
| 2810 | Economy Books Product Mini | Books | $130.14 | 159 | ★ 1.5 | 550 | SKU-002810 |
| 2812 | Super Office Supplies Product Pro | Office Supplies | $616.40 | 261 | ★ 1.5 | 270 | SKU-002812 |
| 2813 | Economy Clothing Product 2024 | Clothing | $471.16 | 496 | ★ 4.3 | 55 | SKU-002813 |
| 2814 | Pro Toys & Games Product Plus | Toys & Games | $638.36 | 213 | ★ 3.8 | 344 | SKU-002814 |
| 2815 | Standard Toys & Games Product XL | Toys & Games | $568.53 | 79 | ★ 3.4 | 835 | SKU-002815 |
| 2816 | Mega Books Product Classic | Books | $529.66 | 478 | ★ 2.5 | 54 | SKU-002816 |
| 2817 | Ultra Health & Beauty Product XL | Health & Beauty | $794.16 | 39 | ★ 3.8 | 985 | SKU-002817 |
| 2818 | Professional Automotive Product XL | Automotive | $718.78 | 79 | ★ 4.0 | 20 | SKU-002818 |
| 2819 | Super Electronics Product 2024 | Electronics | $450.00 | 383 | ★ 1.8 | 696 | SKU-002819 |
| 2820 | Mega Home & Garden Product Pro | Home & Garden | $404.15 | 434 | ★ 1.6 | 768 | SKU-002820 |
| 2821 | Ultra Health & Beauty Product Plus | Health & Beauty | $442.91 | 52 | ★ 2.1 | 294 | SKU-002821 |
| 2822 | Premium Office Supplies Product Classic | Office Supplies | $97.27 | 230 | ★ 2.0 | 52 | SKU-002822 |
| 2823 | Premium Office Supplies Product Plus | Office Supplies | $474.72 | 373 | ★ 3.7 | 208 | SKU-002823 |
| 2824 | Mega Sports & Outdoors Product Pro | Sports & Outdoors | $616.65 | 0 | ★ 3.2 | 559 | SKU-002824 |
| 2826 | Professional Health & Beauty Product Plus | Health & Beauty | $74.48 | 460 | ★ 3.0 | 521 | SKU-002826 |
| 2827 | Professional Toys & Games Product Special Edition | Toys & Games | $254.31 | 218 | ★ 3.1 | 580 | SKU-002827 |
| 2828 | Professional Food & Grocery Product Plus | Food & Grocery | $789.72 | 75 | ★ 3.0 | 425 | SKU-002828 |
| 2830 | Ultra Home & Garden Product Lite | Home & Garden | $541.82 | 378 | ★ 1.5 | 753 | SKU-002830 |
| 2831 | Pro Home & Garden Product Advanced | Home & Garden | $714.95 | 349 | ★ 1.8 | 34 | SKU-002831 |
| 2832 | Ultra Food & Grocery Product XL | Food & Grocery | $809.99 | 44 | ★ 4.2 | 300 | SKU-002832 |
| 2833 | Ultra Toys & Games Product Pro | Toys & Games | $658.19 | 212 | ★ 2.8 | 930 | SKU-002833 |
| 2835 | Mega Health & Beauty Product Max | Health & Beauty | $255.77 | 9 | ★ 4.5 | 978 | SKU-002835 |
| 2836 | Elite Automotive Product Max | Automotive | $645.96 | 449 | ★ 2.7 | 450 | SKU-002836 |
// 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
};
}