Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 360 | Premium Electronics Product Classic | Electronics | $607.55 | 297 | ★ 1.7 | 303 | SKU-000360 |
| 361 | Economy Health & Beauty Product Pro | Health & Beauty | $71.70 | 163 | ★ 1.1 | 729 | SKU-000361 |
| 363 | Standard Electronics Product 2024 | Electronics | $770.25 | 131 | ★ 3.6 | 445 | SKU-000363 |
| 364 | Deluxe Health & Beauty Product Max | Health & Beauty | $303.19 | 223 | ★ 1.7 | 427 | SKU-000364 |
| 365 | Ultra Automotive Product Max | Automotive | $50.03 | 496 | ★ 3.9 | 684 | SKU-000365 |
| 366 | Ultra Food & Grocery Product Max | Food & Grocery | $608.08 | 416 | ★ 3.4 | 275 | SKU-000366 |
| 367 | Premium Office Supplies Product Max | Office Supplies | $699.08 | 465 | ★ 4.1 | 93 | SKU-000367 |
| 368 | Premium Sports & Outdoors Product Special Edition | Sports & Outdoors | $893.61 | 163 | ★ 3.5 | 672 | SKU-000368 |
| 369 | Super Toys & Games Product Lite | Toys & Games | $460.82 | 479 | ★ 4.4 | 843 | SKU-000369 |
| 370 | Ultra Food & Grocery Product Special Edition | Food & Grocery | $494.84 | 355 | ★ 1.6 | 881 | SKU-000370 |
| 371 | Economy Electronics Product XL | Electronics | $959.81 | 483 | ★ 1.5 | 59 | SKU-000371 |
| 372 | Super Sports & Outdoors Product Max | Sports & Outdoors | $50.13 | 22 | ★ 3.3 | 734 | SKU-000372 |
| 373 | Mega Clothing Product XL | Clothing | $814.15 | 127 | ★ 4.8 | 19 | SKU-000373 |
| 374 | Deluxe Office Supplies Product XL | Office Supplies | $422.03 | 371 | ★ 3.8 | 907 | SKU-000374 |
| 375 | Premium Health & Beauty Product Lite | Health & Beauty | $581.33 | 371 | ★ 2.3 | 362 | SKU-000375 |
| 376 | Super Sports & Outdoors Product Max | Sports & Outdoors | $576.15 | 435 | ★ 1.9 | 370 | SKU-000376 |
| 377 | Pro Sports & Outdoors Product Classic | Sports & Outdoors | $490.30 | 277 | ★ 3.1 | 393 | SKU-000377 |
| 378 | Elite Health & Beauty Product Max | Health & Beauty | $247.17 | 476 | ★ 3.9 | 46 | SKU-000378 |
| 379 | Ultra Health & Beauty Product Plus | Health & Beauty | $591.51 | 145 | ★ 2.6 | 812 | SKU-000379 |
| 381 | Super Clothing Product Lite | Clothing | $500.65 | 427 | ★ 1.4 | 713 | SKU-000381 |
| 382 | Standard Food & Grocery Product Lite | Food & Grocery | $860.17 | 274 | ★ 1.9 | 338 | SKU-000382 |
| 383 | Economy Food & Grocery Product Mini | Food & Grocery | $780.99 | 228 | ★ 1.9 | 703 | SKU-000383 |
| 384 | Professional Home & Garden Product XL | Home & Garden | $355.27 | 411 | ★ 3.8 | 925 | SKU-000384 |
| 385 | Super Sports & Outdoors Product Advanced | Sports & Outdoors | $383.02 | 320 | ★ 4.5 | 241 | SKU-000385 |
| 386 | Super Books Product Lite | Books | $575.59 | 417 | ★ 2.6 | 252 | SKU-000386 |
// 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
};
}