Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3455 | Standard Books Product XL | Books | $48.06 | 299 | ★ 4.8 | 271 | SKU-003455 |
| 3456 | Mega Health & Beauty Product Pro | Health & Beauty | $806.16 | 360 | ★ 3.5 | 967 | SKU-003456 |
| 3457 | Pro Food & Grocery Product Pro | Food & Grocery | $469.60 | 96 | ★ 1.5 | 476 | SKU-003457 |
| 3458 | Mega Health & Beauty Product Lite | Health & Beauty | $427.77 | 367 | ★ 4.4 | 520 | SKU-003458 |
| 3459 | Premium Food & Grocery Product Lite | Food & Grocery | $376.59 | 289 | ★ 4.6 | 464 | SKU-003459 |
| 3460 | Premium Health & Beauty Product Plus | Health & Beauty | $102.43 | 274 | ★ 4.3 | 557 | SKU-003460 |
| 3461 | Deluxe Books Product Classic | Books | $371.28 | 89 | ★ 4.6 | 844 | SKU-003461 |
| 3462 | Economy Health & Beauty Product 2024 | Health & Beauty | $31.25 | 216 | ★ 3.8 | 398 | SKU-003462 |
| 3463 | Elite Health & Beauty Product Pro | Health & Beauty | $223.13 | 109 | ★ 2.8 | 427 | SKU-003463 |
| 3464 | Deluxe Sports & Outdoors Product 2024 | Sports & Outdoors | $356.86 | 270 | ★ 2.3 | 339 | SKU-003464 |
| 3465 | Premium Electronics Product Pro | Electronics | $939.15 | 357 | ★ 1.2 | 898 | SKU-003465 |
| 3466 | Deluxe Toys & Games Product Advanced | Toys & Games | $933.88 | 392 | ★ 3.1 | 64 | SKU-003466 |
| 3467 | Elite Sports & Outdoors Product Advanced | Sports & Outdoors | $383.95 | 102 | ★ 4.0 | 106 | SKU-003467 |
| 3468 | Ultra Toys & Games Product Lite | Toys & Games | $72.49 | 181 | ★ 3.8 | 66 | SKU-003468 |
| 3469 | Elite Electronics Product Max | Electronics | $256.52 | 276 | ★ 4.9 | 305 | SKU-003469 |
| 3470 | Professional Food & Grocery Product Classic | Food & Grocery | $370.12 | 228 | ★ 3.5 | 174 | SKU-003470 |
| 3471 | Professional Books Product Mini | Books | $740.08 | 360 | ★ 4.9 | 52 | SKU-003471 |
| 3472 | Super Toys & Games Product Plus | Toys & Games | $437.88 | 356 | ★ 1.4 | 530 | SKU-003472 |
| 3473 | Elite Clothing Product Max | Clothing | $614.29 | 6 | ★ 1.4 | 762 | SKU-003473 |
| 3474 | Pro Health & Beauty Product Special Edition | Health & Beauty | $460.30 | 321 | ★ 3.7 | 573 | SKU-003474 |
| 3475 | Mega Food & Grocery Product Special Edition | Food & Grocery | $866.32 | 96 | ★ 5.0 | 965 | SKU-003475 |
| 3476 | Ultra Office Supplies Product Classic | Office Supplies | $965.40 | 95 | ★ 4.2 | 511 | SKU-003476 |
| 3477 | Pro Health & Beauty Product Advanced | Health & Beauty | $937.95 | 399 | ★ 3.6 | 524 | SKU-003477 |
| 3478 | Economy Home & Garden Product Pro | Home & Garden | $554.98 | 129 | ★ 2.0 | 858 | SKU-003478 |
| 3479 | Ultra Toys & Games Product Mini | Toys & Games | $422.72 | 124 | ★ 3.8 | 129 | SKU-003479 |
// 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
};
}