Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 953 | Ultra Books Product Mini | Books | $569.74 | 209 | ★ 2.7 | 483 | SKU-000953 |
| 954 | Economy Office Supplies Product Classic | Office Supplies | $514.38 | 121 | ★ 4.4 | 488 | SKU-000954 |
| 955 | Pro Clothing Product XL | Clothing | $720.20 | 85 | ★ 4.6 | 939 | SKU-000955 |
| 956 | Standard Food & Grocery Product Max | Food & Grocery | $436.98 | 54 | ★ 3.8 | 266 | SKU-000956 |
| 957 | Elite Food & Grocery Product Pro | Food & Grocery | $195.16 | 246 | ★ 2.2 | 539 | SKU-000957 |
| 958 | Economy Automotive Product Classic | Automotive | $552.14 | 356 | ★ 4.9 | 490 | SKU-000958 |
| 959 | Professional Office Supplies Product Mini | Office Supplies | $587.09 | 308 | ★ 1.7 | 764 | SKU-000959 |
| 960 | Mega Toys & Games Product Advanced | Toys & Games | $528.70 | 170 | ★ 2.1 | 142 | SKU-000960 |
| 961 | Ultra Sports & Outdoors Product Lite | Sports & Outdoors | $758.16 | 432 | ★ 3.4 | 314 | SKU-000961 |
| 962 | Mega Home & Garden Product XL | Home & Garden | $529.59 | 7 | ★ 3.9 | 862 | SKU-000962 |
| 963 | Ultra Automotive Product Special Edition | Automotive | $873.63 | 365 | ★ 4.7 | 20 | SKU-000963 |
| 964 | Deluxe Office Supplies Product Plus | Office Supplies | $928.90 | 460 | ★ 1.1 | 723 | SKU-000964 |
| 966 | Pro Books Product Lite | Books | $563.80 | 388 | ★ 4.1 | 818 | SKU-000966 |
| 967 | Economy Home & Garden Product Mini | Home & Garden | $582.50 | 220 | ★ 2.0 | 130 | SKU-000967 |
| 968 | Pro Clothing Product Plus | Clothing | $981.13 | 334 | ★ 3.5 | 393 | SKU-000968 |
| 969 | Pro Books Product Max | Books | $712.09 | 313 | ★ 3.5 | 100 | SKU-000969 |
| 971 | Pro Clothing Product Max | Clothing | $699.63 | 464 | ★ 1.2 | 428 | SKU-000971 |
| 972 | Professional Home & Garden Product Plus | Home & Garden | $456.36 | 43 | ★ 1.4 | 83 | SKU-000972 |
| 973 | Mega Sports & Outdoors Product Special Edition | Sports & Outdoors | $893.03 | 491 | ★ 4.2 | 196 | SKU-000973 |
| 974 | Standard Clothing Product 2024 | Clothing | $438.05 | 446 | ★ 3.3 | 368 | SKU-000974 |
| 975 | Premium Clothing Product Max | Clothing | $872.94 | 281 | ★ 3.4 | 809 | SKU-000975 |
| 976 | Super Sports & Outdoors Product Special Edition | Sports & Outdoors | $954.74 | 291 | ★ 2.4 | 487 | SKU-000976 |
| 977 | Elite Electronics Product Classic | Electronics | $673.63 | 185 | ★ 4.5 | 64 | SKU-000977 |
| 978 | Standard Toys & Games Product Pro | Toys & Games | $666.97 | 155 | ★ 4.9 | 93 | SKU-000978 |
| 980 | Standard Office Supplies Product Lite | Office Supplies | $201.67 | 376 | ★ 4.9 | 7 | SKU-000980 |
// 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
};
}