Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4358 | Ultra Automotive Product XL | Automotive | $608.21 | 308 | ★ 3.9 | 243 | SKU-004358 |
| 4361 | Premium Sports & Outdoors Product Plus | Sports & Outdoors | $300.50 | 247 | ★ 4.4 | 825 | SKU-004361 |
| 4362 | Standard Clothing Product Advanced | Clothing | $666.40 | 84 | ★ 3.8 | 872 | SKU-004362 |
| 4363 | Super Food & Grocery Product Plus | Food & Grocery | $735.54 | 312 | ★ 1.3 | 72 | SKU-004363 |
| 4364 | Economy Electronics Product XL | Electronics | $589.21 | 150 | ★ 1.9 | 667 | SKU-004364 |
| 4365 | Deluxe Office Supplies Product Mini | Office Supplies | $682.91 | 407 | ★ 4.6 | 966 | SKU-004365 |
| 4366 | Premium Sports & Outdoors Product 2024 | Sports & Outdoors | $348.91 | 235 | ★ 1.4 | 983 | SKU-004366 |
| 4367 | Pro Health & Beauty Product Pro | Health & Beauty | $79.27 | 152 | ★ 3.7 | 592 | SKU-004367 |
| 4368 | Mega Home & Garden Product 2024 | Home & Garden | $709.16 | 228 | ★ 1.2 | 782 | SKU-004368 |
| 4369 | Ultra Health & Beauty Product Advanced | Health & Beauty | $485.71 | 399 | ★ 4.9 | 68 | SKU-004369 |
| 4370 | Mega Sports & Outdoors Product XL | Sports & Outdoors | $321.94 | 173 | ★ 1.1 | 620 | SKU-004370 |
| 4371 | Pro Toys & Games Product Mini | Toys & Games | $923.73 | 231 | ★ 3.6 | 246 | SKU-004371 |
| 4372 | Standard Health & Beauty Product Advanced | Health & Beauty | $201.72 | 43 | ★ 2.3 | 334 | SKU-004372 |
| 4375 | Super Electronics Product Plus | Electronics | $738.16 | 92 | ★ 2.8 | 46 | SKU-004375 |
| 4376 | Ultra Health & Beauty Product Classic | Health & Beauty | $373.63 | 447 | ★ 3.2 | 699 | SKU-004376 |
| 4377 | Super Office Supplies Product Max | Office Supplies | $653.99 | 300 | ★ 3.4 | 951 | SKU-004377 |
| 4378 | Pro Sports & Outdoors Product Plus | Sports & Outdoors | $854.22 | 411 | ★ 3.5 | 750 | SKU-004378 |
| 4379 | Professional Health & Beauty Product Advanced | Health & Beauty | $672.76 | 490 | ★ 1.6 | 895 | SKU-004379 |
| 4381 | Super Toys & Games Product Mini | Toys & Games | $627.51 | 46 | ★ 1.1 | 222 | SKU-004381 |
| 4382 | Economy Office Supplies Product Pro | Office Supplies | $15.47 | 134 | ★ 1.5 | 382 | SKU-004382 |
| 4383 | Economy Office Supplies Product 2024 | Office Supplies | $583.44 | 17 | ★ 1.4 | 327 | SKU-004383 |
| 4384 | Premium Books Product Max | Books | $610.50 | 123 | ★ 1.7 | 690 | SKU-004384 |
| 4385 | Professional Toys & Games Product Lite | Toys & Games | $213.41 | 344 | ★ 3.8 | 27 | SKU-004385 |
| 4386 | Deluxe Home & Garden Product Pro | Home & Garden | $793.69 | 295 | ★ 4.3 | 462 | SKU-004386 |
| 4387 | Deluxe Office Supplies Product Special Edition | Office Supplies | $333.82 | 29 | ★ 4.2 | 569 | SKU-004387 |
// 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
};
}