Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3958 | Mega Health & Beauty Product Max | Health & Beauty | $146.43 | 398 | ★ 3.7 | 563 | SKU-003958 |
| 3959 | Ultra Books Product 2024 | Books | $890.80 | 63 | ★ 4.3 | 958 | SKU-003959 |
| 3960 | Premium Clothing Product Pro | Clothing | $72.72 | 212 | ★ 2.2 | 441 | SKU-003960 |
| 3961 | Mega Food & Grocery Product Max | Food & Grocery | $460.98 | 313 | ★ 3.6 | 747 | SKU-003961 |
| 3962 | Economy Sports & Outdoors Product 2024 | Sports & Outdoors | $640.56 | 66 | ★ 2.8 | 845 | SKU-003962 |
| 3963 | Super Home & Garden Product Plus | Home & Garden | $597.37 | 468 | ★ 2.3 | 689 | SKU-003963 |
| 3964 | Professional Food & Grocery Product Plus | Food & Grocery | $216.34 | 165 | ★ 1.0 | 46 | SKU-003964 |
| 3965 | Standard Clothing Product Plus | Clothing | $463.20 | 406 | ★ 2.2 | 837 | SKU-003965 |
| 3966 | Premium Office Supplies Product XL | Office Supplies | $820.02 | 246 | ★ 2.2 | 910 | SKU-003966 |
| 3968 | Standard Food & Grocery Product Advanced | Food & Grocery | $912.32 | 478 | ★ 3.2 | 735 | SKU-003968 |
| 3969 | Standard Office Supplies Product 2024 | Office Supplies | $296.43 | 404 | ★ 4.4 | 795 | SKU-003969 |
| 3970 | Premium Office Supplies Product Mini | Office Supplies | $766.56 | 348 | ★ 2.9 | 339 | SKU-003970 |
| 3971 | Professional Office Supplies Product Plus | Office Supplies | $660.36 | 172 | ★ 4.4 | 716 | SKU-003971 |
| 3972 | Economy Food & Grocery Product Advanced | Food & Grocery | $701.32 | 212 | ★ 4.2 | 149 | SKU-003972 |
| 3973 | Mega Books Product Special Edition | Books | $927.65 | 158 | ★ 3.4 | 179 | SKU-003973 |
| 3975 | Deluxe Office Supplies Product Classic | Office Supplies | $382.41 | 168 | ★ 1.3 | 604 | SKU-003975 |
| 3976 | Pro Clothing Product Plus | Clothing | $775.83 | 376 | ★ 3.3 | 611 | SKU-003976 |
| 3977 | Elite Automotive Product Pro | Automotive | $606.41 | 114 | ★ 1.8 | 601 | SKU-003977 |
| 3979 | Super Toys & Games Product Pro | Toys & Games | $123.73 | 56 | ★ 4.3 | 323 | SKU-003979 |
| 3980 | Mega Sports & Outdoors Product 2024 | Sports & Outdoors | $98.18 | 404 | ★ 2.4 | 519 | SKU-003980 |
| 3981 | Standard Sports & Outdoors Product Mini | Sports & Outdoors | $117.33 | 272 | ★ 3.3 | 769 | SKU-003981 |
| 3982 | Premium Health & Beauty Product Classic | Health & Beauty | $725.60 | 409 | ★ 1.6 | 714 | SKU-003982 |
| 3983 | Standard Automotive Product Pro | Automotive | $864.08 | 287 | ★ 3.3 | 703 | SKU-003983 |
| 3984 | Pro Home & Garden Product Classic | Home & Garden | $173.71 | 151 | ★ 2.9 | 766 | SKU-003984 |
| 3985 | Pro Clothing Product Mini | Clothing | $694.71 | 95 | ★ 1.9 | 347 | SKU-003985 |
// 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
};
}