Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1951 | Deluxe Office Supplies Product Advanced | Office Supplies | $838.33 | 145 | ★ 2.4 | 550 | SKU-001951 |
| 1952 | Elite Automotive Product Lite | Automotive | $85.33 | 247 | ★ 1.7 | 638 | SKU-001952 |
| 1954 | Pro Home & Garden Product Advanced | Home & Garden | $614.85 | 243 | ★ 1.9 | 322 | SKU-001954 |
| 1955 | Mega Clothing Product Lite | Clothing | $163.53 | 170 | ★ 1.6 | 643 | SKU-001955 |
| 1956 | Ultra Clothing Product Max | Clothing | $175.75 | 167 | ★ 3.0 | 167 | SKU-001956 |
| 1957 | Elite Health & Beauty Product Mini | Health & Beauty | $205.95 | 54 | ★ 4.4 | 435 | SKU-001957 |
| 1958 | Pro Books Product XL | Books | $521.66 | 22 | ★ 2.1 | 979 | SKU-001958 |
| 1959 | Mega Automotive Product 2024 | Automotive | $45.89 | 217 | ★ 2.9 | 760 | SKU-001959 |
| 1960 | Premium Electronics Product 2024 | Electronics | $792.16 | 454 | ★ 3.6 | 451 | SKU-001960 |
| 1961 | Premium Automotive Product Classic | Automotive | $248.46 | 72 | ★ 1.2 | 519 | SKU-001961 |
| 1962 | Mega Sports & Outdoors Product Classic | Sports & Outdoors | $819.75 | 266 | ★ 4.0 | 664 | SKU-001962 |
| 1963 | Ultra Toys & Games Product Mini | Toys & Games | $182.26 | 413 | ★ 1.8 | 373 | SKU-001963 |
| 1964 | Pro Clothing Product XL | Clothing | $104.83 | 82 | ★ 1.1 | 474 | SKU-001964 |
| 1965 | Mega Toys & Games Product Lite | Toys & Games | $498.86 | 255 | ★ 2.3 | 141 | SKU-001965 |
| 1966 | Elite Electronics Product Special Edition | Electronics | $69.37 | 211 | ★ 3.3 | 898 | SKU-001966 |
| 1967 | Premium Health & Beauty Product Special Edition | Health & Beauty | $780.00 | 480 | ★ 1.3 | 175 | SKU-001967 |
| 1968 | Professional Health & Beauty Product Plus | Health & Beauty | $274.97 | 415 | ★ 4.4 | 368 | SKU-001968 |
| 1969 | Professional Toys & Games Product Mini | Toys & Games | $407.27 | 13 | ★ 4.2 | 602 | SKU-001969 |
| 1970 | Pro Clothing Product Special Edition | Clothing | $75.12 | 33 | ★ 1.3 | 206 | SKU-001970 |
| 1971 | Elite Home & Garden Product Special Edition | Home & Garden | $865.56 | 410 | ★ 3.7 | 63 | SKU-001971 |
| 1972 | Deluxe Electronics Product Special Edition | Electronics | $136.25 | 495 | ★ 1.6 | 53 | SKU-001972 |
| 1974 | Deluxe Home & Garden Product 2024 | Home & Garden | $980.80 | 290 | ★ 1.1 | 304 | SKU-001974 |
| 1975 | Super Toys & Games Product Advanced | Toys & Games | $756.96 | 245 | ★ 1.4 | 917 | SKU-001975 |
| 1976 | Premium Health & Beauty Product Plus | Health & Beauty | $414.85 | 301 | ★ 1.6 | 519 | SKU-001976 |
| 1978 | Pro Clothing Product Mini | Clothing | $544.81 | 309 | ★ 2.8 | 605 | SKU-001978 |
// 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
};
}