Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4247 | Super Food & Grocery Product XL | Food & Grocery | $618.60 | 288 | ★ 1.4 | 821 | SKU-004247 |
| 4248 | Economy Electronics Product XL | Electronics | $354.68 | 244 | ★ 2.0 | 418 | SKU-004248 |
| 4249 | Ultra Books Product Plus | Books | $987.64 | 95 | ★ 2.5 | 42 | SKU-004249 |
| 4250 | Pro Health & Beauty Product Plus | Health & Beauty | $643.28 | 178 | ★ 2.2 | 719 | SKU-004250 |
| 4251 | Deluxe Health & Beauty Product Mini | Health & Beauty | $176.20 | 451 | ★ 4.8 | 167 | SKU-004251 |
| 4252 | Deluxe Office Supplies Product 2024 | Office Supplies | $922.39 | 319 | ★ 3.1 | 370 | SKU-004252 |
| 4253 | Standard Toys & Games Product Lite | Toys & Games | $537.40 | 379 | ★ 2.4 | 321 | SKU-004253 |
| 4254 | Elite Books Product XL | Books | $565.89 | 379 | ★ 4.0 | 677 | SKU-004254 |
| 4255 | Super Clothing Product 2024 | Clothing | $632.02 | 74 | ★ 2.1 | 719 | SKU-004255 |
| 4257 | Premium Sports & Outdoors Product Special Edition | Sports & Outdoors | $747.32 | 354 | ★ 3.5 | 631 | SKU-004257 |
| 4258 | Standard Health & Beauty Product Max | Health & Beauty | $148.08 | 195 | ★ 4.3 | 674 | SKU-004258 |
| 4259 | Ultra Electronics Product Mini | Electronics | $456.35 | 166 | ★ 4.0 | 500 | SKU-004259 |
| 4260 | Ultra Electronics Product Lite | Electronics | $213.26 | 484 | ★ 2.8 | 963 | SKU-004260 |
| 4261 | Elite Toys & Games Product Advanced | Toys & Games | $321.08 | 377 | ★ 1.3 | 979 | SKU-004261 |
| 4262 | Super Electronics Product XL | Electronics | $317.26 | 49 | ★ 2.8 | 702 | SKU-004262 |
| 4263 | Ultra Health & Beauty Product Lite | Health & Beauty | $783.75 | 338 | ★ 2.5 | 915 | SKU-004263 |
| 4264 | Standard Books Product Classic | Books | $161.16 | 3 | ★ 2.6 | 729 | SKU-004264 |
| 4265 | Ultra Electronics Product Mini | Electronics | $888.78 | 151 | ★ 1.7 | 217 | SKU-004265 |
| 4266 | Pro Toys & Games Product Lite | Toys & Games | $230.69 | 482 | ★ 1.1 | 354 | SKU-004266 |
| 4267 | Mega Office Supplies Product Plus | Office Supplies | $438.55 | 206 | ★ 1.4 | 187 | SKU-004267 |
| 4268 | Professional Health & Beauty Product Lite | Health & Beauty | $252.20 | 7 | ★ 1.3 | 802 | SKU-004268 |
| 4269 | Premium Books Product Mini | Books | $508.38 | 374 | ★ 2.5 | 464 | SKU-004269 |
| 4270 | Mega Clothing Product Classic | Clothing | $810.57 | 416 | ★ 3.4 | 610 | SKU-004270 |
| 4271 | Professional Sports & Outdoors Product Advanced | Sports & Outdoors | $143.12 | 404 | ★ 3.9 | 926 | SKU-004271 |
| 4272 | Deluxe Office Supplies Product Pro | Office Supplies | $810.92 | 113 | ★ 2.6 | 893 | SKU-004272 |
// 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
};
}