Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 558 | Deluxe Health & Beauty Product Lite | Health & Beauty | $420.61 | 214 | ★ 4.7 | 673 | SKU-000558 |
| 559 | Standard Food & Grocery Product XL | Food & Grocery | $911.41 | 102 | ★ 3.1 | 973 | SKU-000559 |
| 560 | Professional Electronics Product Advanced | Electronics | $779.95 | 374 | ★ 4.2 | 912 | SKU-000560 |
| 561 | Ultra Office Supplies Product XL | Office Supplies | $520.25 | 366 | ★ 1.2 | 493 | SKU-000561 |
| 563 | Standard Home & Garden Product XL | Home & Garden | $731.91 | 476 | ★ 2.2 | 329 | SKU-000563 |
| 564 | Economy Books Product Max | Books | $590.87 | 359 | ★ 2.6 | 282 | SKU-000564 |
| 567 | Professional Home & Garden Product Max | Home & Garden | $284.90 | 154 | ★ 3.6 | 436 | SKU-000567 |
| 568 | Deluxe Home & Garden Product 2024 | Home & Garden | $51.93 | 86 | ★ 4.5 | 524 | SKU-000568 |
| 569 | Elite Toys & Games Product Mini | Toys & Games | $728.69 | 360 | ★ 1.6 | 676 | SKU-000569 |
| 570 | Super Electronics Product Max | Electronics | $383.22 | 395 | ★ 1.7 | 665 | SKU-000570 |
| 571 | Ultra Books Product Pro | Books | $54.16 | 370 | ★ 2.3 | 47 | SKU-000571 |
| 572 | Deluxe Toys & Games Product Max | Toys & Games | $923.45 | 94 | ★ 1.7 | 760 | SKU-000572 |
| 573 | Ultra Food & Grocery Product Classic | Food & Grocery | $454.31 | 449 | ★ 2.8 | 37 | SKU-000573 |
| 575 | Mega Clothing Product Advanced | Clothing | $974.36 | 298 | ★ 3.8 | 184 | SKU-000575 |
| 576 | Super Office Supplies Product XL | Office Supplies | $67.64 | 35 | ★ 3.2 | 427 | SKU-000576 |
| 577 | Ultra Sports & Outdoors Product Advanced | Sports & Outdoors | $64.77 | 414 | ★ 1.7 | 310 | SKU-000577 |
| 578 | Economy Electronics Product Pro | Electronics | $877.15 | 477 | ★ 2.5 | 454 | SKU-000578 |
| 579 | Mega Home & Garden Product Pro | Home & Garden | $395.84 | 293 | ★ 2.5 | 114 | SKU-000579 |
| 581 | Ultra Office Supplies Product Pro | Office Supplies | $698.20 | 205 | ★ 1.8 | 557 | SKU-000581 |
| 582 | Professional Clothing Product Max | Clothing | $266.87 | 91 | ★ 1.5 | 351 | SKU-000582 |
| 583 | Elite Automotive Product XL | Automotive | $240.07 | 403 | ★ 1.2 | 147 | SKU-000583 |
| 584 | Premium Automotive Product Lite | Automotive | $181.58 | 441 | ★ 4.7 | 771 | SKU-000584 |
| 585 | Standard Books Product Pro | Books | $708.75 | 432 | ★ 2.4 | 203 | SKU-000585 |
| 586 | Deluxe Health & Beauty Product Pro | Health & Beauty | $33.87 | 390 | ★ 4.7 | 395 | SKU-000586 |
| 587 | Mega Automotive Product Mini | Automotive | $112.19 | 231 | ★ 2.8 | 85 | SKU-000587 |
// 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
};
}