Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 839 | Standard Food & Grocery Product Advanced | Food & Grocery | $223.92 | 445 | ★ 1.7 | 878 | SKU-000839 |
| 840 | Premium Food & Grocery Product Plus | Food & Grocery | $449.92 | 457 | ★ 2.4 | 222 | SKU-000840 |
| 841 | Mega Office Supplies Product Advanced | Office Supplies | $431.00 | 53 | ★ 1.1 | 310 | SKU-000841 |
| 843 | Mega Automotive Product Plus | Automotive | $764.71 | 412 | ★ 3.3 | 17 | SKU-000843 |
| 844 | Premium Office Supplies Product Max | Office Supplies | $585.81 | 281 | ★ 4.0 | 660 | SKU-000844 |
| 845 | Premium Automotive Product Advanced | Automotive | $214.94 | 233 | ★ 3.2 | 282 | SKU-000845 |
| 846 | Ultra Electronics Product XL | Electronics | $584.53 | 140 | ★ 2.0 | 930 | SKU-000846 |
| 848 | Pro Food & Grocery Product Special Edition | Food & Grocery | $986.07 | 234 | ★ 4.0 | 353 | SKU-000848 |
| 849 | Mega Office Supplies Product Classic | Office Supplies | $590.15 | 499 | ★ 2.0 | 465 | SKU-000849 |
| 850 | Standard Food & Grocery Product Plus | Food & Grocery | $714.12 | 226 | ★ 2.1 | 655 | SKU-000850 |
| 851 | Premium Sports & Outdoors Product Advanced | Sports & Outdoors | $825.79 | 135 | ★ 1.1 | 151 | SKU-000851 |
| 852 | Deluxe Toys & Games Product Pro | Toys & Games | $448.83 | 74 | ★ 1.6 | 895 | SKU-000852 |
| 853 | Mega Food & Grocery Product Mini | Food & Grocery | $212.90 | 225 | ★ 2.6 | 39 | SKU-000853 |
| 854 | Pro Electronics Product Pro | Electronics | $885.10 | 193 | ★ 1.4 | 683 | SKU-000854 |
| 855 | Premium Electronics Product Advanced | Electronics | $873.54 | 80 | ★ 1.3 | 461 | SKU-000855 |
| 856 | Deluxe Toys & Games Product 2024 | Toys & Games | $103.23 | 61 | ★ 4.2 | 159 | SKU-000856 |
| 857 | Mega Toys & Games Product 2024 | Toys & Games | $75.73 | 398 | ★ 3.7 | 0 | SKU-000857 |
| 858 | Pro Health & Beauty Product 2024 | Health & Beauty | $810.19 | 313 | ★ 2.1 | 540 | SKU-000858 |
| 859 | Economy Electronics Product Pro | Electronics | $683.35 | 236 | ★ 1.5 | 887 | SKU-000859 |
| 860 | Super Toys & Games Product Max | Toys & Games | $285.37 | 468 | ★ 1.7 | 274 | SKU-000860 |
| 861 | Pro Office Supplies Product Lite | Office Supplies | $915.80 | 201 | ★ 3.5 | 968 | SKU-000861 |
| 862 | Super Books Product XL | Books | $261.38 | 78 | ★ 1.9 | 257 | SKU-000862 |
| 864 | Professional Books Product Plus | Books | $942.17 | 133 | ★ 2.0 | 907 | SKU-000864 |
| 865 | Elite Food & Grocery Product 2024 | Food & Grocery | $485.21 | 264 | ★ 2.6 | 170 | SKU-000865 |
| 866 | Pro Clothing Product 2024 | Clothing | $838.96 | 38 | ★ 1.1 | 574 | SKU-000866 |
// 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
};
}