Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3509 | Economy Health & Beauty Product Max | Health & Beauty | $136.42 | 161 | ★ 2.8 | 914 | SKU-003509 |
| 3510 | Super Office Supplies Product Max | Office Supplies | $95.92 | 409 | ★ 1.2 | 472 | SKU-003510 |
| 3511 | Deluxe Toys & Games Product Classic | Toys & Games | $942.15 | 277 | ★ 1.5 | 505 | SKU-003511 |
| 3512 | Premium Clothing Product Lite | Clothing | $809.09 | 15 | ★ 3.7 | 298 | SKU-003512 |
| 3514 | Elite Home & Garden Product Max | Home & Garden | $741.43 | 97 | ★ 3.1 | 459 | SKU-003514 |
| 3515 | Elite Books Product Mini | Books | $201.05 | 289 | ★ 1.5 | 773 | SKU-003515 |
| 3516 | Standard Home & Garden Product 2024 | Home & Garden | $542.22 | 310 | ★ 4.6 | 259 | SKU-003516 |
| 3517 | Standard Electronics Product Max | Electronics | $826.60 | 151 | ★ 2.3 | 737 | SKU-003517 |
| 3518 | Elite Sports & Outdoors Product Plus | Sports & Outdoors | $516.35 | 408 | ★ 3.7 | 969 | SKU-003518 |
| 3519 | Mega Office Supplies Product Mini | Office Supplies | $251.91 | 480 | ★ 4.0 | 718 | SKU-003519 |
| 3520 | Elite Office Supplies Product Pro | Office Supplies | $297.06 | 201 | ★ 1.2 | 272 | SKU-003520 |
| 3521 | Mega Toys & Games Product Mini | Toys & Games | $12.63 | 480 | ★ 1.6 | 924 | SKU-003521 |
| 3522 | Deluxe Automotive Product Mini | Automotive | $588.25 | 457 | ★ 3.7 | 474 | SKU-003522 |
| 3523 | Standard Office Supplies Product 2024 | Office Supplies | $582.69 | 84 | ★ 2.0 | 416 | SKU-003523 |
| 3524 | Mega Electronics Product Mini | Electronics | $40.37 | 100 | ★ 4.1 | 26 | SKU-003524 |
| 3525 | Elite Electronics Product Advanced | Electronics | $229.00 | 472 | ★ 3.5 | 213 | SKU-003525 |
| 3527 | Elite Electronics Product Max | Electronics | $666.67 | 303 | ★ 3.9 | 332 | SKU-003527 |
| 3528 | Professional Food & Grocery Product Advanced | Food & Grocery | $251.57 | 259 | ★ 2.7 | 117 | SKU-003528 |
| 3529 | Pro Sports & Outdoors Product Plus | Sports & Outdoors | $159.53 | 161 | ★ 1.8 | 953 | SKU-003529 |
| 3530 | Ultra Automotive Product Mini | Automotive | $948.04 | 435 | ★ 2.7 | 248 | SKU-003530 |
| 3531 | Elite Toys & Games Product 2024 | Toys & Games | $867.64 | 291 | ★ 4.2 | 338 | SKU-003531 |
| 3532 | Mega Food & Grocery Product Mini | Food & Grocery | $655.72 | 89 | ★ 3.8 | 983 | SKU-003532 |
| 3533 | Mega Toys & Games Product Lite | Toys & Games | $621.40 | 251 | ★ 2.4 | 918 | SKU-003533 |
| 3535 | Economy Electronics Product Advanced | Electronics | $332.35 | 396 | ★ 3.0 | 870 | SKU-003535 |
| 3536 | Super Sports & Outdoors Product 2024 | Sports & Outdoors | $437.86 | 94 | ★ 1.9 | 467 | SKU-003536 |
// 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
};
}