Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2503 | Ultra Electronics Product Pro | Electronics | $866.19 | 25 | ★ 4.9 | 929 | SKU-002503 |
| 2504 | Ultra Books Product XL | Books | $834.06 | 51 | ★ 4.7 | 145 | SKU-002504 |
| 2505 | Economy Automotive Product XL | Automotive | $601.28 | 76 | ★ 3.6 | 514 | SKU-002505 |
| 2506 | Mega Sports & Outdoors Product Special Edition | Sports & Outdoors | $630.45 | 190 | ★ 5.0 | 322 | SKU-002506 |
| 2507 | Standard Toys & Games Product 2024 | Toys & Games | $146.80 | 178 | ★ 1.2 | 485 | SKU-002507 |
| 2508 | Super Books Product Plus | Books | $806.77 | 420 | ★ 4.1 | 156 | SKU-002508 |
| 2509 | Mega Office Supplies Product Pro | Office Supplies | $625.10 | 493 | ★ 3.4 | 209 | SKU-002509 |
| 2510 | Economy Electronics Product Pro | Electronics | $906.74 | 227 | ★ 1.3 | 218 | SKU-002510 |
| 2511 | Premium Clothing Product 2024 | Clothing | $140.23 | 458 | ★ 1.6 | 573 | SKU-002511 |
| 2512 | Super Food & Grocery Product Special Edition | Food & Grocery | $445.41 | 18 | ★ 2.0 | 285 | SKU-002512 |
| 2513 | Ultra Home & Garden Product Lite | Home & Garden | $360.84 | 48 | ★ 1.9 | 475 | SKU-002513 |
| 2514 | Mega Clothing Product Advanced | Clothing | $691.86 | 287 | ★ 4.0 | 3 | SKU-002514 |
| 2515 | Pro Food & Grocery Product Special Edition | Food & Grocery | $42.01 | 240 | ★ 3.5 | 965 | SKU-002515 |
| 2516 | Ultra Electronics Product Plus | Electronics | $546.21 | 293 | ★ 2.2 | 578 | SKU-002516 |
| 2517 | Ultra Automotive Product Special Edition | Automotive | $288.96 | 280 | ★ 3.5 | 259 | SKU-002517 |
| 2518 | Super Sports & Outdoors Product Advanced | Sports & Outdoors | $817.83 | 88 | ★ 1.6 | 860 | SKU-002518 |
| 2519 | Economy Electronics Product Classic | Electronics | $634.52 | 409 | ★ 3.2 | 136 | SKU-002519 |
| 2520 | Economy Books Product Classic | Books | $212.39 | 59 | ★ 3.5 | 541 | SKU-002520 |
| 2521 | Premium Toys & Games Product Special Edition | Toys & Games | $614.56 | 489 | ★ 4.6 | 747 | SKU-002521 |
| 2522 | Elite Health & Beauty Product Lite | Health & Beauty | $419.04 | 82 | ★ 3.5 | 940 | SKU-002522 |
| 2523 | Ultra Clothing Product Plus | Clothing | $206.51 | 60 | ★ 3.2 | 969 | SKU-002523 |
| 2524 | Pro Automotive Product Plus | Automotive | $45.22 | 217 | ★ 3.4 | 30 | SKU-002524 |
| 2525 | Elite Clothing Product Special Edition | Clothing | $305.00 | 15 | ★ 4.6 | 461 | SKU-002525 |
| 2526 | Economy Automotive Product Classic | Automotive | $369.97 | 449 | ★ 2.5 | 212 | SKU-002526 |
| 2527 | Premium Toys & Games Product Pro | Toys & Games | $42.35 | 299 | ★ 4.8 | 124 | SKU-002527 |
// 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
};
}