Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 701 | Ultra Electronics Product Advanced | Electronics | $143.87 | 180 | ★ 1.5 | 980 | SKU-000701 |
| 702 | Ultra Automotive Product Plus | Automotive | $456.45 | 359 | ★ 2.2 | 518 | SKU-000702 |
| 703 | Pro Electronics Product Pro | Electronics | $526.63 | 409 | ★ 3.8 | 858 | SKU-000703 |
| 704 | Elite Electronics Product XL | Electronics | $844.16 | 493 | ★ 3.1 | 714 | SKU-000704 |
| 705 | Mega Toys & Games Product Plus | Toys & Games | $874.13 | 436 | ★ 2.5 | 566 | SKU-000705 |
| 707 | Mega Office Supplies Product Pro | Office Supplies | $189.54 | 463 | ★ 1.0 | 169 | SKU-000707 |
| 708 | Ultra Toys & Games Product Advanced | Toys & Games | $233.66 | 76 | ★ 4.8 | 709 | SKU-000708 |
| 709 | Ultra Toys & Games Product Advanced | Toys & Games | $825.67 | 380 | ★ 1.3 | 714 | SKU-000709 |
| 710 | Premium Electronics Product XL | Electronics | $75.94 | 110 | ★ 3.5 | 450 | SKU-000710 |
| 711 | Elite Sports & Outdoors Product Plus | Sports & Outdoors | $591.34 | 238 | ★ 2.8 | 631 | SKU-000711 |
| 712 | Elite Electronics Product Lite | Electronics | $121.43 | 7 | ★ 4.4 | 518 | SKU-000712 |
| 713 | Ultra Health & Beauty Product Plus | Health & Beauty | $132.72 | 495 | ★ 3.2 | 699 | SKU-000713 |
| 714 | Ultra Sports & Outdoors Product 2024 | Sports & Outdoors | $722.71 | 317 | ★ 4.1 | 855 | SKU-000714 |
| 715 | Super Home & Garden Product XL | Home & Garden | $442.54 | 278 | ★ 3.9 | 125 | SKU-000715 |
| 716 | Professional Books Product Mini | Books | $990.24 | 332 | ★ 2.3 | 934 | SKU-000716 |
| 717 | Super Automotive Product Special Edition | Automotive | $549.44 | 215 | ★ 4.4 | 649 | SKU-000717 |
| 718 | Pro Books Product Lite | Books | $715.86 | 315 | ★ 1.3 | 808 | SKU-000718 |
| 719 | Standard Clothing Product Max | Clothing | $634.33 | 356 | ★ 2.9 | 26 | SKU-000719 |
| 720 | Ultra Office Supplies Product Classic | Office Supplies | $936.60 | 17 | ★ 3.8 | 605 | SKU-000720 |
| 721 | Professional Health & Beauty Product Classic | Health & Beauty | $906.89 | 24 | ★ 4.7 | 613 | SKU-000721 |
| 722 | Standard Sports & Outdoors Product Pro | Sports & Outdoors | $369.30 | 70 | ★ 3.4 | 176 | SKU-000722 |
| 723 | Pro Sports & Outdoors Product Pro | Sports & Outdoors | $647.19 | 47 | ★ 4.4 | 499 | SKU-000723 |
| 724 | Deluxe Books Product Mini | Books | $776.85 | 194 | ★ 1.5 | 781 | SKU-000724 |
| 725 | Premium Electronics Product Classic | Electronics | $957.98 | 278 | ★ 3.0 | 76 | SKU-000725 |
| 726 | Ultra Clothing Product Classic | Clothing | $834.43 | 58 | ★ 4.3 | 244 | SKU-000726 |
// 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
};
}