Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3537 | Pro Home & Garden Product Plus | Home & Garden | $27.27 | 440 | ★ 3.7 | 89 | SKU-003537 |
| 3540 | Ultra Electronics Product Plus | Electronics | $791.53 | 128 | ★ 2.9 | 609 | SKU-003540 |
| 3541 | Premium Toys & Games Product Classic | Toys & Games | $112.54 | 192 | ★ 3.7 | 214 | SKU-003541 |
| 3542 | Deluxe Food & Grocery Product Classic | Food & Grocery | $802.77 | 293 | ★ 4.5 | 30 | SKU-003542 |
| 3543 | Pro Books Product Max | Books | $881.00 | 109 | ★ 3.5 | 465 | SKU-003543 |
| 3545 | Economy Automotive Product Pro | Automotive | $814.63 | 145 | ★ 1.8 | 250 | SKU-003545 |
| 3546 | Deluxe Books Product Pro | Books | $833.38 | 289 | ★ 1.3 | 366 | SKU-003546 |
| 3547 | Deluxe Sports & Outdoors Product Mini | Sports & Outdoors | $737.10 | 395 | ★ 1.2 | 910 | SKU-003547 |
| 3548 | Standard Sports & Outdoors Product Pro | Sports & Outdoors | $664.90 | 206 | ★ 2.4 | 630 | SKU-003548 |
| 3550 | Economy Home & Garden Product Plus | Home & Garden | $37.86 | 298 | ★ 3.6 | 708 | SKU-003550 |
| 3551 | Economy Clothing Product Special Edition | Clothing | $380.03 | 69 | ★ 3.5 | 18 | SKU-003551 |
| 3552 | Ultra Electronics Product 2024 | Electronics | $716.92 | 60 | ★ 2.1 | 580 | SKU-003552 |
| 3553 | Standard Electronics Product Mini | Electronics | $995.75 | 213 | ★ 4.9 | 426 | SKU-003553 |
| 3554 | Economy Health & Beauty Product Plus | Health & Beauty | $111.52 | 261 | ★ 1.9 | 515 | SKU-003554 |
| 3555 | Economy Automotive Product Mini | Automotive | $698.46 | 373 | ★ 4.5 | 77 | SKU-003555 |
| 3557 | Pro Automotive Product Mini | Automotive | $101.87 | 172 | ★ 3.1 | 540 | SKU-003557 |
| 3558 | Mega Electronics Product Mini | Electronics | $231.75 | 390 | ★ 4.1 | 119 | SKU-003558 |
| 3559 | Premium Office Supplies Product Plus | Office Supplies | $272.16 | 374 | ★ 2.4 | 896 | SKU-003559 |
| 3560 | Elite Office Supplies Product Mini | Office Supplies | $337.84 | 156 | ★ 3.8 | 758 | SKU-003560 |
| 3561 | Elite Health & Beauty Product Max | Health & Beauty | $791.18 | 443 | ★ 4.2 | 978 | SKU-003561 |
| 3562 | Economy Sports & Outdoors Product XL | Sports & Outdoors | $487.21 | 491 | ★ 3.8 | 553 | SKU-003562 |
| 3563 | Ultra Sports & Outdoors Product Pro | Sports & Outdoors | $98.76 | 237 | ★ 2.5 | 71 | SKU-003563 |
| 3564 | Elite Books Product XL | Books | $491.55 | 467 | ★ 2.9 | 243 | SKU-003564 |
| 3565 | Standard Automotive Product Pro | Automotive | $743.88 | 32 | ★ 4.0 | 659 | SKU-003565 |
| 3566 | Economy Clothing Product Max | Clothing | $279.55 | 273 | ★ 2.8 | 584 | SKU-003566 |
// 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
};
}