Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2945 | Standard Clothing Product Plus | Clothing | $878.99 | 25 | ★ 1.5 | 496 | SKU-002945 |
| 2946 | Mega Home & Garden Product XL | Home & Garden | $37.90 | 259 | ★ 2.5 | 423 | SKU-002946 |
| 2947 | Super Sports & Outdoors Product Mini | Sports & Outdoors | $748.73 | 208 | ★ 1.7 | 336 | SKU-002947 |
| 2948 | Economy Sports & Outdoors Product Classic | Sports & Outdoors | $38.58 | 362 | ★ 2.5 | 415 | SKU-002948 |
| 2949 | Professional Food & Grocery Product Plus | Food & Grocery | $142.80 | 239 | ★ 2.0 | 161 | SKU-002949 |
| 2950 | Economy Toys & Games Product Plus | Toys & Games | $423.26 | 247 | ★ 1.8 | 350 | SKU-002950 |
| 2951 | Ultra Home & Garden Product Special Edition | Home & Garden | $299.23 | 288 | ★ 4.8 | 852 | SKU-002951 |
| 2952 | Professional Electronics Product Classic | Electronics | $427.97 | 396 | ★ 2.7 | 746 | SKU-002952 |
| 2953 | Deluxe Home & Garden Product Advanced | Home & Garden | $944.18 | 317 | ★ 1.7 | 970 | SKU-002953 |
| 2954 | Economy Books Product Special Edition | Books | $410.96 | 255 | ★ 3.8 | 901 | SKU-002954 |
| 2955 | Elite Sports & Outdoors Product Plus | Sports & Outdoors | $19.41 | 232 | ★ 3.5 | 530 | SKU-002955 |
| 2956 | Standard Home & Garden Product Lite | Home & Garden | $398.35 | 422 | ★ 2.6 | 563 | SKU-002956 |
| 2957 | Mega Toys & Games Product Max | Toys & Games | $599.31 | 108 | ★ 2.6 | 377 | SKU-002957 |
| 2958 | Professional Home & Garden Product Classic | Home & Garden | $809.09 | 241 | ★ 2.3 | 374 | SKU-002958 |
| 2959 | Deluxe Health & Beauty Product Mini | Health & Beauty | $435.94 | 93 | ★ 4.8 | 307 | SKU-002959 |
| 2960 | Standard Electronics Product Special Edition | Electronics | $955.50 | 317 | ★ 2.6 | 917 | SKU-002960 |
| 2961 | Premium Electronics Product 2024 | Electronics | $406.47 | 450 | ★ 3.5 | 426 | SKU-002961 |
| 2962 | Pro Office Supplies Product Special Edition | Office Supplies | $621.32 | 305 | ★ 1.0 | 941 | SKU-002962 |
| 2963 | Economy Office Supplies Product Max | Office Supplies | $437.32 | 50 | ★ 3.0 | 33 | SKU-002963 |
| 2964 | Mega Home & Garden Product 2024 | Home & Garden | $528.19 | 492 | ★ 4.1 | 868 | SKU-002964 |
| 2965 | Standard Home & Garden Product Pro | Home & Garden | $769.76 | 386 | ★ 4.9 | 690 | SKU-002965 |
| 2966 | Standard Automotive Product Pro | Automotive | $966.42 | 258 | ★ 3.3 | 770 | SKU-002966 |
| 2967 | Premium Electronics Product Mini | Electronics | $640.40 | 128 | ★ 2.1 | 361 | SKU-002967 |
| 2968 | Ultra Health & Beauty Product 2024 | Health & Beauty | $824.66 | 36 | ★ 1.7 | 436 | SKU-002968 |
| 2969 | Ultra Food & Grocery Product Mini | Food & Grocery | $550.63 | 393 | ★ 3.3 | 814 | SKU-002969 |
// 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
};
}