Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1448 | Ultra Health & Beauty Product Plus | Health & Beauty | $287.03 | 195 | ★ 4.1 | 259 | SKU-001448 |
| 1449 | Deluxe Electronics Product Mini | Electronics | $107.89 | 278 | ★ 1.8 | 954 | SKU-001449 |
| 1450 | Professional Automotive Product XL | Automotive | $286.24 | 308 | ★ 4.2 | 840 | SKU-001450 |
| 1451 | Mega Home & Garden Product Mini | Home & Garden | $897.73 | 313 | ★ 3.0 | 96 | SKU-001451 |
| 1452 | Professional Toys & Games Product Plus | Toys & Games | $848.92 | 254 | ★ 2.0 | 592 | SKU-001452 |
| 1453 | Pro Electronics Product Mini | Electronics | $805.46 | 325 | ★ 2.5 | 918 | SKU-001453 |
| 1454 | Premium Office Supplies Product Pro | Office Supplies | $433.53 | 426 | ★ 2.8 | 368 | SKU-001454 |
| 1455 | Professional Health & Beauty Product Lite | Health & Beauty | $720.10 | 20 | ★ 2.8 | 163 | SKU-001455 |
| 1456 | Pro Health & Beauty Product Classic | Health & Beauty | $511.04 | 113 | ★ 3.5 | 3 | SKU-001456 |
| 1457 | Premium Electronics Product Mini | Electronics | $220.21 | 65 | ★ 2.5 | 262 | SKU-001457 |
| 1458 | Professional Books Product 2024 | Books | $409.14 | 6 | ★ 2.9 | 864 | SKU-001458 |
| 1459 | Deluxe Office Supplies Product Advanced | Office Supplies | $307.02 | 167 | ★ 2.7 | 363 | SKU-001459 |
| 1461 | Elite Food & Grocery Product 2024 | Food & Grocery | $329.89 | 422 | ★ 3.6 | 374 | SKU-001461 |
| 1462 | Standard Toys & Games Product XL | Toys & Games | $925.16 | 432 | ★ 3.4 | 527 | SKU-001462 |
| 1463 | Standard Sports & Outdoors Product Max | Sports & Outdoors | $450.51 | 271 | ★ 2.8 | 133 | SKU-001463 |
| 1464 | Deluxe Home & Garden Product Mini | Home & Garden | $685.21 | 397 | ★ 2.5 | 813 | SKU-001464 |
| 1465 | Premium Food & Grocery Product Classic | Food & Grocery | $571.85 | 459 | ★ 3.7 | 746 | SKU-001465 |
| 1466 | Standard Home & Garden Product Plus | Home & Garden | $224.83 | 259 | ★ 4.9 | 737 | SKU-001466 |
| 1467 | Deluxe Food & Grocery Product Classic | Food & Grocery | $403.78 | 13 | ★ 3.6 | 991 | SKU-001467 |
| 1468 | Standard Books Product Classic | Books | $135.48 | 399 | ★ 3.6 | 446 | SKU-001468 |
| 1469 | Professional Home & Garden Product Special Edition | Home & Garden | $848.17 | 45 | ★ 1.5 | 628 | SKU-001469 |
| 1470 | Standard Electronics Product Max | Electronics | $815.22 | 67 | ★ 2.6 | 468 | SKU-001470 |
| 1472 | Super Toys & Games Product Pro | Toys & Games | $194.85 | 207 | ★ 5.0 | 643 | SKU-001472 |
| 1473 | Economy Toys & Games Product Advanced | Toys & Games | $539.48 | 479 | ★ 2.9 | 454 | SKU-001473 |
| 1474 | Elite Health & Beauty Product Plus | Health & Beauty | $557.19 | 499 | ★ 3.8 | 215 | SKU-001474 |
// 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
};
}