Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2643 | Economy Toys & Games Product 2024 | Toys & Games | $899.22 | 348 | ★ 2.3 | 615 | SKU-002643 |
| 2644 | Pro Clothing Product Plus | Clothing | $242.47 | 81 | ★ 2.3 | 714 | SKU-002644 |
| 2645 | Standard Electronics Product Special Edition | Electronics | $407.94 | 325 | ★ 4.2 | 325 | SKU-002645 |
| 2646 | Professional Toys & Games Product Plus | Toys & Games | $82.49 | 89 | ★ 2.0 | 632 | SKU-002646 |
| 2647 | Mega Automotive Product Advanced | Automotive | $542.02 | 106 | ★ 1.7 | 657 | SKU-002647 |
| 2648 | Premium Health & Beauty Product Max | Health & Beauty | $128.56 | 242 | ★ 2.4 | 814 | SKU-002648 |
| 2649 | Mega Automotive Product Special Edition | Automotive | $965.69 | 10 | ★ 3.5 | 112 | SKU-002649 |
| 2650 | Pro Automotive Product Lite | Automotive | $347.47 | 170 | ★ 2.1 | 663 | SKU-002650 |
| 2651 | Super Food & Grocery Product Special Edition | Food & Grocery | $64.40 | 403 | ★ 2.2 | 29 | SKU-002651 |
| 2652 | Deluxe Automotive Product Special Edition | Automotive | $750.87 | 288 | ★ 2.7 | 757 | SKU-002652 |
| 2653 | Super Electronics Product 2024 | Electronics | $810.86 | 369 | ★ 2.6 | 662 | SKU-002653 |
| 2654 | Mega Food & Grocery Product Pro | Food & Grocery | $139.10 | 117 | ★ 1.9 | 289 | SKU-002654 |
| 2655 | Super Automotive Product Plus | Automotive | $472.79 | 205 | ★ 4.0 | 218 | SKU-002655 |
| 2656 | Pro Health & Beauty Product Lite | Health & Beauty | $866.04 | 332 | ★ 1.2 | 180 | SKU-002656 |
| 2657 | Standard Clothing Product Max | Clothing | $620.41 | 376 | ★ 3.4 | 788 | SKU-002657 |
| 2658 | Professional Automotive Product Special Edition | Automotive | $834.84 | 80 | ★ 3.4 | 964 | SKU-002658 |
| 2659 | Ultra Food & Grocery Product Mini | Food & Grocery | $402.87 | 468 | ★ 3.8 | 469 | SKU-002659 |
| 2660 | Economy Clothing Product XL | Clothing | $488.25 | 192 | ★ 1.6 | 688 | SKU-002660 |
| 2661 | Professional Office Supplies Product Classic | Office Supplies | $910.74 | 301 | ★ 3.3 | 661 | SKU-002661 |
| 2662 | Super Sports & Outdoors Product Pro | Sports & Outdoors | $249.76 | 211 | ★ 2.7 | 184 | SKU-002662 |
| 2663 | Deluxe Home & Garden Product Advanced | Home & Garden | $801.64 | 11 | ★ 5.0 | 446 | SKU-002663 |
| 2665 | Economy Home & Garden Product Mini | Home & Garden | $134.83 | 305 | ★ 4.6 | 996 | SKU-002665 |
| 2666 | Deluxe Books Product Classic | Books | $600.35 | 434 | ★ 2.7 | 636 | SKU-002666 |
| 2667 | Pro Food & Grocery Product Max | Food & Grocery | $610.00 | 150 | ★ 2.3 | 216 | SKU-002667 |
| 2668 | Standard Home & Garden Product Special Edition | Home & Garden | $277.98 | 58 | ★ 1.2 | 824 | SKU-002668 |
// 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
};
}