Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4506 | Super Sports & Outdoors Product Classic | Sports & Outdoors | $854.75 | 325 | ★ 2.9 | 900 | SKU-004506 |
| 4508 | Mega Clothing Product XL | Clothing | $219.25 | 283 | ★ 2.8 | 87 | SKU-004508 |
| 4509 | Pro Books Product 2024 | Books | $383.16 | 354 | ★ 3.6 | 656 | SKU-004509 |
| 4510 | Mega Home & Garden Product Plus | Home & Garden | $80.15 | 73 | ★ 4.3 | 636 | SKU-004510 |
| 4511 | Pro Toys & Games Product Advanced | Toys & Games | $12.99 | 128 | ★ 2.1 | 991 | SKU-004511 |
| 4512 | Premium Books Product Plus | Books | $351.45 | 208 | ★ 2.4 | 931 | SKU-004512 |
| 4513 | Standard Toys & Games Product XL | Toys & Games | $544.49 | 82 | ★ 4.2 | 295 | SKU-004513 |
| 4516 | Ultra Home & Garden Product Max | Home & Garden | $12.19 | 33 | ★ 3.7 | 792 | SKU-004516 |
| 4517 | Standard Electronics Product 2024 | Electronics | $21.91 | 146 | ★ 4.3 | 724 | SKU-004517 |
| 4518 | Elite Food & Grocery Product Mini | Food & Grocery | $849.04 | 247 | ★ 2.6 | 878 | SKU-004518 |
| 4519 | Elite Books Product 2024 | Books | $465.53 | 257 | ★ 4.4 | 509 | SKU-004519 |
| 4520 | Elite Office Supplies Product Classic | Office Supplies | $768.85 | 342 | ★ 2.8 | 983 | SKU-004520 |
| 4521 | Professional Home & Garden Product Max | Home & Garden | $927.03 | 280 | ★ 1.1 | 332 | SKU-004521 |
| 4522 | Elite Electronics Product Lite | Electronics | $685.25 | 128 | ★ 3.7 | 282 | SKU-004522 |
| 4523 | Pro Electronics Product Plus | Electronics | $921.84 | 304 | ★ 3.9 | 422 | SKU-004523 |
| 4525 | Economy Books Product Plus | Books | $691.94 | 119 | ★ 1.5 | 177 | SKU-004525 |
| 4526 | Mega Clothing Product 2024 | Clothing | $653.72 | 348 | ★ 2.0 | 999 | SKU-004526 |
| 4527 | Economy Sports & Outdoors Product Classic | Sports & Outdoors | $378.70 | 267 | ★ 3.5 | 932 | SKU-004527 |
| 4528 | Economy Toys & Games Product XL | Toys & Games | $787.78 | 495 | ★ 2.5 | 937 | SKU-004528 |
| 4529 | Professional Health & Beauty Product Advanced | Health & Beauty | $861.38 | 494 | ★ 4.4 | 726 | SKU-004529 |
| 4530 | Economy Clothing Product Advanced | Clothing | $959.89 | 329 | ★ 2.4 | 280 | SKU-004530 |
| 4531 | Professional Office Supplies Product Max | Office Supplies | $750.21 | 486 | ★ 3.9 | 244 | SKU-004531 |
| 4532 | Super Toys & Games Product Plus | Toys & Games | $370.31 | 98 | ★ 2.8 | 31 | SKU-004532 |
| 4533 | Professional Home & Garden Product Special Edition | Home & Garden | $496.02 | 180 | ★ 4.6 | 287 | SKU-004533 |
| 4534 | Ultra Automotive Product Mini | Automotive | $811.81 | 34 | ★ 3.0 | 140 | SKU-004534 |
// 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
};
}