Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2917 | Professional Electronics Product Plus | Electronics | $331.98 | 208 | ★ 4.1 | 464 | SKU-002917 |
| 2918 | Ultra Electronics Product Classic | Electronics | $719.84 | 484 | ★ 2.4 | 703 | SKU-002918 |
| 2919 | Ultra Electronics Product Plus | Electronics | $209.92 | 23 | ★ 4.8 | 655 | SKU-002919 |
| 2920 | Ultra Health & Beauty Product Plus | Health & Beauty | $660.29 | 134 | ★ 4.0 | 951 | SKU-002920 |
| 2921 | Mega Health & Beauty Product 2024 | Health & Beauty | $768.38 | 92 | ★ 3.2 | 942 | SKU-002921 |
| 2922 | Economy Books Product Plus | Books | $753.90 | 441 | ★ 1.1 | 55 | SKU-002922 |
| 2923 | Standard Sports & Outdoors Product Lite | Sports & Outdoors | $733.57 | 401 | ★ 1.1 | 168 | SKU-002923 |
| 2924 | Super Automotive Product Max | Automotive | $27.52 | 154 | ★ 3.5 | 639 | SKU-002924 |
| 2925 | Premium Electronics Product Max | Electronics | $660.83 | 87 | ★ 2.9 | 561 | SKU-002925 |
| 2926 | Elite Electronics Product Classic | Electronics | $856.88 | 18 | ★ 2.9 | 166 | SKU-002926 |
| 2927 | Ultra Electronics Product Lite | Electronics | $786.57 | 495 | ★ 3.6 | 816 | SKU-002927 |
| 2928 | Mega Home & Garden Product Lite | Home & Garden | $601.52 | 392 | ★ 4.6 | 989 | SKU-002928 |
| 2929 | Ultra Health & Beauty Product Plus | Health & Beauty | $267.81 | 27 | ★ 2.9 | 185 | SKU-002929 |
| 2931 | Elite Sports & Outdoors Product Mini | Sports & Outdoors | $771.64 | 142 | ★ 2.1 | 46 | SKU-002931 |
| 2932 | Professional Toys & Games Product Classic | Toys & Games | $671.47 | 71 | ★ 1.7 | 733 | SKU-002932 |
| 2933 | Standard Toys & Games Product Special Edition | Toys & Games | $937.97 | 433 | ★ 2.0 | 58 | SKU-002933 |
| 2935 | Super Books Product Mini | Books | $532.36 | 74 | ★ 3.9 | 82 | SKU-002935 |
| 2936 | Premium Toys & Games Product Advanced | Toys & Games | $353.92 | 423 | ★ 4.5 | 408 | SKU-002936 |
| 2937 | Deluxe Clothing Product Special Edition | Clothing | $148.88 | 458 | ★ 1.9 | 304 | SKU-002937 |
| 2938 | Pro Home & Garden Product Pro | Home & Garden | $772.46 | 395 | ★ 1.9 | 20 | SKU-002938 |
| 2939 | Professional Electronics Product Mini | Electronics | $286.41 | 44 | ★ 1.9 | 864 | SKU-002939 |
| 2940 | Elite Clothing Product Plus | Clothing | $213.69 | 264 | ★ 1.1 | 675 | SKU-002940 |
| 2941 | Deluxe Home & Garden Product 2024 | Home & Garden | $951.74 | 234 | ★ 1.9 | 639 | SKU-002941 |
| 2942 | Premium Sports & Outdoors Product Pro | Sports & Outdoors | $615.66 | 127 | ★ 2.8 | 84 | SKU-002942 |
| 2944 | Ultra Home & Garden Product Mini | Home & Garden | $302.17 | 461 | ★ 4.9 | 632 | SKU-002944 |
// 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
};
}