Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2585 | Ultra Toys & Games Product XL | Toys & Games | $578.76 | 468 | ★ 4.0 | 810 | SKU-002585 |
| 2586 | Pro Clothing Product Special Edition | Clothing | $544.13 | 24 | ★ 1.5 | 79 | SKU-002586 |
| 2587 | Elite Clothing Product Classic | Clothing | $831.69 | 410 | ★ 1.5 | 896 | SKU-002587 |
| 2588 | Mega Clothing Product Advanced | Clothing | $801.36 | 268 | ★ 2.8 | 166 | SKU-002588 |
| 2589 | Economy Health & Beauty Product Pro | Health & Beauty | $309.64 | 126 | ★ 1.9 | 216 | SKU-002589 |
| 2592 | Standard Sports & Outdoors Product Pro | Sports & Outdoors | $877.62 | 333 | ★ 4.9 | 822 | SKU-002592 |
| 2593 | Elite Toys & Games Product Max | Toys & Games | $266.35 | 220 | ★ 3.7 | 538 | SKU-002593 |
| 2594 | Deluxe Home & Garden Product Mini | Home & Garden | $164.46 | 46 | ★ 1.1 | 153 | SKU-002594 |
| 2595 | Professional Food & Grocery Product Plus | Food & Grocery | $580.48 | 10 | ★ 3.5 | 264 | SKU-002595 |
| 2596 | Super Health & Beauty Product Classic | Health & Beauty | $856.48 | 79 | ★ 2.3 | 4 | SKU-002596 |
| 2597 | Pro Clothing Product Special Edition | Clothing | $427.95 | 450 | ★ 3.7 | 238 | SKU-002597 |
| 2598 | Elite Sports & Outdoors Product Mini | Sports & Outdoors | $752.43 | 37 | ★ 1.5 | 123 | SKU-002598 |
| 2599 | Ultra Clothing Product 2024 | Clothing | $559.37 | 480 | ★ 2.3 | 855 | SKU-002599 |
| 2601 | Professional Office Supplies Product Plus | Office Supplies | $824.29 | 74 | ★ 2.3 | 886 | SKU-002601 |
| 2602 | Super Sports & Outdoors Product XL | Sports & Outdoors | $693.72 | 369 | ★ 3.7 | 55 | SKU-002602 |
| 2603 | Professional Electronics Product Advanced | Electronics | $112.71 | 497 | ★ 1.6 | 504 | SKU-002603 |
| 2604 | Standard Electronics Product Classic | Electronics | $910.26 | 201 | ★ 2.7 | 505 | SKU-002604 |
| 2606 | Elite Books Product Advanced | Books | $150.25 | 180 | ★ 3.8 | 349 | SKU-002606 |
| 2607 | Pro Automotive Product Pro | Automotive | $204.06 | 87 | ★ 2.6 | 834 | SKU-002607 |
| 2609 | Ultra Sports & Outdoors Product Classic | Sports & Outdoors | $308.62 | 191 | ★ 2.2 | 368 | SKU-002609 |
| 2610 | Super Books Product Max | Books | $623.93 | 153 | ★ 4.6 | 86 | SKU-002610 |
| 2611 | Premium Books Product Classic | Books | $867.78 | 151 | ★ 3.6 | 779 | SKU-002611 |
| 2613 | Professional Automotive Product Pro | Automotive | $662.25 | 488 | ★ 4.1 | 760 | SKU-002613 |
| 2614 | Pro Clothing Product Classic | Clothing | $414.19 | 309 | ★ 2.9 | 303 | SKU-002614 |
| 2615 | Economy Sports & Outdoors Product Max | Sports & Outdoors | $979.41 | 78 | ★ 4.8 | 718 | SKU-002615 |
| 2616 | Super Electronics Product Pro | Electronics | $117.87 | 384 | ★ 1.1 | 414 | SKU-002616 |
| 2617 | Pro Toys & Games Product Pro | Toys & Games | $222.82 | 250 | ★ 2.9 | 182 | SKU-002617 |
| 2619 | Economy Books Product Advanced | Books | $671.07 | 471 | ★ 3.1 | 709 | SKU-002619 |
| 2620 | Standard Food & Grocery Product Pro | Food & Grocery | $285.55 | 4 | ★ 3.2 | 356 | SKU-002620 |
| 2621 | Premium Automotive Product Mini | Automotive | $55.88 | 125 | ★ 3.1 | 716 | SKU-002621 |
| 2622 | Standard Sports & Outdoors Product Pro | Sports & Outdoors | $295.56 | 111 | ★ 4.3 | 19 | SKU-002622 |
| 2623 | Deluxe Sports & Outdoors Product Max | Sports & Outdoors | $850.66 | 381 | ★ 2.2 | 745 | SKU-002623 |
| 2624 | Pro Health & Beauty Product Advanced | Health & Beauty | $718.83 | 1 | ★ 4.7 | 667 | SKU-002624 |
| 2625 | Premium Electronics Product Advanced | Electronics | $877.59 | 339 | ★ 4.8 | 410 | SKU-002625 |
| 2627 | Ultra Automotive Product Advanced | Automotive | $703.40 | 439 | ★ 4.6 | 811 | SKU-002627 |
| 2628 | Economy Automotive Product Pro | Automotive | $506.45 | 472 | ★ 1.8 | 351 | SKU-002628 |
| 2629 | Elite Toys & Games Product Lite | Toys & Games | $207.55 | 399 | ★ 4.6 | 201 | SKU-002629 |
| 2630 | Mega Sports & Outdoors Product Classic | Sports & Outdoors | $187.97 | 460 | ★ 4.9 | 130 | SKU-002630 |
| 2631 | Deluxe Clothing Product Advanced | Clothing | $185.64 | 176 | ★ 4.6 | 761 | SKU-002631 |
| 2632 | Ultra Clothing Product Classic | Clothing | $797.13 | 290 | ★ 2.5 | 555 | SKU-002632 |
| 2633 | Elite Health & Beauty Product Advanced | Health & Beauty | $243.38 | 345 | ★ 4.9 | 270 | SKU-002633 |
| 2634 | Ultra Office Supplies Product XL | Office Supplies | $894.19 | 229 | ★ 3.7 | 744 | SKU-002634 |
| 2635 | Deluxe Food & Grocery Product Pro | Food & Grocery | $818.24 | 286 | ★ 4.7 | 213 | SKU-002635 |
| 2636 | Standard Electronics Product Advanced | Electronics | $801.45 | 91 | ★ 4.7 | 554 | SKU-002636 |
| 2637 | Pro Home & Garden Product Advanced | Home & Garden | $434.23 | 429 | ★ 4.5 | 688 | SKU-002637 |
| 2638 | Mega Clothing Product Advanced | Clothing | $372.13 | 71 | ★ 4.3 | 3 | SKU-002638 |
| 2639 | Ultra Sports & Outdoors Product Special Edition | Sports & Outdoors | $442.73 | 382 | ★ 2.1 | 965 | SKU-002639 |
| 2640 | Ultra Clothing Product Classic | Clothing | $954.55 | 177 | ★ 4.0 | 415 | SKU-002640 |
| 2641 | Professional Clothing Product Lite | Clothing | $718.28 | 201 | ★ 1.6 | 711 | SKU-002641 |
| 2642 | Mega Sports & Outdoors Product 2024 | Sports & Outdoors | $87.13 | 450 | ★ 4.3 | 757 | SKU-002642 |
// 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
};
}