Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4765 | Super Automotive Product Lite | Automotive | $955.61 | 267 | ★ 3.6 | 734 | SKU-004765 |
| 4766 | Ultra Toys & Games Product Plus | Toys & Games | $386.47 | 197 | ★ 3.7 | 88 | SKU-004766 |
| 4767 | Standard Food & Grocery Product XL | Food & Grocery | $166.17 | 49 | ★ 1.1 | 997 | SKU-004767 |
| 4768 | Standard Clothing Product Advanced | Clothing | $647.79 | 319 | ★ 3.5 | 947 | SKU-004768 |
| 4769 | Pro Home & Garden Product Pro | Home & Garden | $197.16 | 415 | ★ 1.4 | 962 | SKU-004769 |
| 4770 | Elite Books Product Max | Books | $727.33 | 368 | ★ 3.3 | 340 | SKU-004770 |
| 4772 | Mega Toys & Games Product XL | Toys & Games | $372.31 | 50 | ★ 3.4 | 901 | SKU-004772 |
| 4773 | Pro Sports & Outdoors Product Pro | Sports & Outdoors | $652.36 | 491 | ★ 2.4 | 133 | SKU-004773 |
| 4774 | Premium Sports & Outdoors Product Special Edition | Sports & Outdoors | $168.87 | 122 | ★ 4.5 | 632 | SKU-004774 |
| 4775 | Premium Health & Beauty Product Mini | Health & Beauty | $90.89 | 388 | ★ 1.8 | 946 | SKU-004775 |
| 4776 | Elite Toys & Games Product Lite | Toys & Games | $25.69 | 277 | ★ 1.3 | 398 | SKU-004776 |
| 4777 | Super Clothing Product XL | Clothing | $546.42 | 438 | ★ 3.3 | 278 | SKU-004777 |
| 4778 | Premium Home & Garden Product XL | Home & Garden | $94.37 | 51 | ★ 2.6 | 799 | SKU-004778 |
| 4779 | Economy Health & Beauty Product Mini | Health & Beauty | $801.90 | 37 | ★ 3.6 | 993 | SKU-004779 |
| 4780 | Professional Clothing Product Pro | Clothing | $873.20 | 161 | ★ 4.6 | 294 | SKU-004780 |
| 4781 | Ultra Health & Beauty Product Special Edition | Health & Beauty | $232.90 | 357 | ★ 3.1 | 955 | SKU-004781 |
| 4782 | Deluxe Office Supplies Product XL | Office Supplies | $679.31 | 286 | ★ 5.0 | 390 | SKU-004782 |
| 4783 | Pro Automotive Product 2024 | Automotive | $321.77 | 134 | ★ 1.8 | 380 | SKU-004783 |
| 4784 | Mega Office Supplies Product Pro | Office Supplies | $787.83 | 332 | ★ 2.0 | 806 | SKU-004784 |
| 4785 | Professional Clothing Product Mini | Clothing | $317.79 | 125 | ★ 2.1 | 667 | SKU-004785 |
| 4786 | Pro Books Product Max | Books | $501.46 | 464 | ★ 4.3 | 233 | SKU-004786 |
| 4787 | Ultra Clothing Product Pro | Clothing | $289.14 | 214 | ★ 1.7 | 951 | SKU-004787 |
| 4788 | Standard Food & Grocery Product Plus | Food & Grocery | $761.35 | 266 | ★ 3.6 | 864 | SKU-004788 |
| 4789 | Deluxe Home & Garden Product Advanced | Home & Garden | $826.75 | 139 | ★ 4.6 | 338 | SKU-004789 |
| 4790 | Mega Food & Grocery Product 2024 | Food & Grocery | $478.16 | 24 | ★ 3.6 | 346 | SKU-004790 |
// 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
};
}