Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1923 | Professional Food & Grocery Product XL | Food & Grocery | $190.84 | 258 | ★ 2.1 | 552 | SKU-001923 |
| 1924 | Super Electronics Product 2024 | Electronics | $788.66 | 44 | ★ 3.3 | 980 | SKU-001924 |
| 1926 | Ultra Home & Garden Product Advanced | Home & Garden | $538.56 | 455 | ★ 4.6 | 434 | SKU-001926 |
| 1927 | Elite Health & Beauty Product Plus | Health & Beauty | $301.21 | 426 | ★ 1.8 | 282 | SKU-001927 |
| 1928 | Economy Food & Grocery Product Pro | Food & Grocery | $496.38 | 269 | ★ 1.3 | 856 | SKU-001928 |
| 1929 | Professional Home & Garden Product Max | Home & Garden | $799.02 | 467 | ★ 2.1 | 30 | SKU-001929 |
| 1930 | Economy Automotive Product Special Edition | Automotive | $321.08 | 108 | ★ 4.3 | 977 | SKU-001930 |
| 1931 | Professional Home & Garden Product Special Edition | Home & Garden | $337.79 | 61 | ★ 3.9 | 662 | SKU-001931 |
| 1932 | Standard Electronics Product Lite | Electronics | $151.53 | 390 | ★ 1.7 | 18 | SKU-001932 |
| 1933 | Standard Books Product Max | Books | $252.95 | 192 | ★ 3.4 | 428 | SKU-001933 |
| 1934 | Deluxe Toys & Games Product Lite | Toys & Games | $188.56 | 194 | ★ 1.2 | 101 | SKU-001934 |
| 1935 | Professional Office Supplies Product Advanced | Office Supplies | $193.56 | 457 | ★ 2.3 | 266 | SKU-001935 |
| 1936 | Deluxe Toys & Games Product Pro | Toys & Games | $731.74 | 22 | ★ 4.2 | 705 | SKU-001936 |
| 1937 | Deluxe Toys & Games Product Advanced | Toys & Games | $758.12 | 499 | ★ 2.9 | 949 | SKU-001937 |
| 1938 | Pro Office Supplies Product Pro | Office Supplies | $110.47 | 426 | ★ 1.5 | 830 | SKU-001938 |
| 1939 | Deluxe Toys & Games Product XL | Toys & Games | $589.13 | 382 | ★ 4.0 | 853 | SKU-001939 |
| 1940 | Pro Food & Grocery Product Plus | Food & Grocery | $569.86 | 412 | ★ 1.1 | 156 | SKU-001940 |
| 1941 | Mega Toys & Games Product Advanced | Toys & Games | $191.85 | 254 | ★ 4.3 | 199 | SKU-001941 |
| 1942 | Ultra Home & Garden Product Classic | Home & Garden | $226.68 | 287 | ★ 4.1 | 175 | SKU-001942 |
| 1943 | Standard Sports & Outdoors Product Lite | Sports & Outdoors | $737.71 | 415 | ★ 4.9 | 738 | SKU-001943 |
| 1945 | Deluxe Food & Grocery Product Advanced | Food & Grocery | $803.89 | 203 | ★ 3.2 | 650 | SKU-001945 |
| 1946 | Ultra Electronics Product Advanced | Electronics | $280.16 | 159 | ★ 4.0 | 931 | SKU-001946 |
| 1948 | Ultra Books Product 2024 | Books | $622.42 | 450 | ★ 3.1 | 396 | SKU-001948 |
| 1949 | Professional Health & Beauty Product 2024 | Health & Beauty | $425.75 | 218 | ★ 2.8 | 826 | SKU-001949 |
| 1950 | Super Home & Garden Product Lite | Home & Garden | $805.14 | 133 | ★ 1.1 | 753 | SKU-001950 |
// 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
};
}