Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3567 | Economy Office Supplies Product Pro | Office Supplies | $152.83 | 59 | ★ 4.9 | 412 | SKU-003567 |
| 3568 | Super Sports & Outdoors Product Max | Sports & Outdoors | $70.02 | 202 | ★ 2.8 | 841 | SKU-003568 |
| 3569 | Mega Toys & Games Product Pro | Toys & Games | $656.00 | 79 | ★ 5.0 | 360 | SKU-003569 |
| 3570 | Pro Sports & Outdoors Product Classic | Sports & Outdoors | $399.41 | 241 | ★ 4.2 | 475 | SKU-003570 |
| 3571 | Ultra Books Product XL | Books | $449.33 | 111 | ★ 2.4 | 758 | SKU-003571 |
| 3572 | Elite Home & Garden Product Max | Home & Garden | $248.84 | 420 | ★ 2.4 | 596 | SKU-003572 |
| 3573 | Premium Clothing Product 2024 | Clothing | $35.69 | 164 | ★ 2.2 | 525 | SKU-003573 |
| 3574 | Economy Office Supplies Product Mini | Office Supplies | $108.38 | 423 | ★ 4.0 | 219 | SKU-003574 |
| 3576 | Super Electronics Product Classic | Electronics | $500.67 | 254 | ★ 2.8 | 459 | SKU-003576 |
| 3578 | Deluxe Toys & Games Product Advanced | Toys & Games | $40.79 | 467 | ★ 1.2 | 36 | SKU-003578 |
| 3579 | Elite Books Product XL | Books | $575.81 | 468 | ★ 1.1 | 94 | SKU-003579 |
| 3580 | Ultra Office Supplies Product Pro | Office Supplies | $716.57 | 472 | ★ 1.6 | 13 | SKU-003580 |
| 3581 | Standard Electronics Product Pro | Electronics | $396.28 | 437 | ★ 1.5 | 525 | SKU-003581 |
| 3582 | Pro Automotive Product Max | Automotive | $684.70 | 39 | ★ 1.9 | 856 | SKU-003582 |
| 3583 | Deluxe Clothing Product Special Edition | Clothing | $228.56 | 267 | ★ 4.9 | 177 | SKU-003583 |
| 3585 | Mega Electronics Product Special Edition | Electronics | $496.06 | 163 | ★ 1.3 | 742 | SKU-003585 |
| 3586 | Ultra Health & Beauty Product Mini | Health & Beauty | $209.07 | 50 | ★ 2.8 | 315 | SKU-003586 |
| 3587 | Mega Food & Grocery Product Pro | Food & Grocery | $129.25 | 70 | ★ 4.1 | 766 | SKU-003587 |
| 3588 | Deluxe Automotive Product Special Edition | Automotive | $358.74 | 226 | ★ 2.6 | 340 | SKU-003588 |
| 3589 | Pro Home & Garden Product Mini | Home & Garden | $605.53 | 353 | ★ 4.8 | 999 | SKU-003589 |
| 3590 | Super Toys & Games Product Lite | Toys & Games | $365.61 | 92 | ★ 2.3 | 686 | SKU-003590 |
| 3591 | Professional Health & Beauty Product Mini | Health & Beauty | $378.04 | 438 | ★ 1.0 | 219 | SKU-003591 |
| 3592 | Pro Clothing Product Special Edition | Clothing | $33.22 | 265 | ★ 1.8 | 85 | SKU-003592 |
| 3594 | Economy Clothing Product Classic | Clothing | $998.34 | 497 | ★ 3.8 | 350 | SKU-003594 |
| 3595 | Economy Electronics Product Classic | Electronics | $758.68 | 181 | ★ 3.4 | 841 | SKU-003595 |
// 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
};
}