Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1009 | Elite Books Product Lite | Books | $452.43 | 458 | ★ 3.3 | 256 | SKU-001009 |
| 1010 | Mega Office Supplies Product Lite | Office Supplies | $655.10 | 376 | ★ 3.4 | 896 | SKU-001010 |
| 1012 | Pro Food & Grocery Product Classic | Food & Grocery | $960.45 | 146 | ★ 1.4 | 241 | SKU-001012 |
| 1013 | Standard Electronics Product XL | Electronics | $653.71 | 323 | ★ 1.8 | 572 | SKU-001013 |
| 1015 | Elite Toys & Games Product Max | Toys & Games | $661.83 | 85 | ★ 2.7 | 689 | SKU-001015 |
| 1016 | Economy Automotive Product Pro | Automotive | $569.78 | 33 | ★ 4.4 | 305 | SKU-001016 |
| 1017 | Elite Electronics Product Classic | Electronics | $573.84 | 455 | ★ 1.4 | 626 | SKU-001017 |
| 1018 | Ultra Home & Garden Product 2024 | Home & Garden | $365.65 | 86 | ★ 2.4 | 686 | SKU-001018 |
| 1019 | Premium Home & Garden Product Classic | Home & Garden | $863.39 | 467 | ★ 3.0 | 837 | SKU-001019 |
| 1020 | Elite Home & Garden Product Lite | Home & Garden | $464.07 | 7 | ★ 2.5 | 99 | SKU-001020 |
| 1021 | Deluxe Automotive Product 2024 | Automotive | $687.74 | 386 | ★ 3.2 | 235 | SKU-001021 |
| 1022 | Super Sports & Outdoors Product XL | Sports & Outdoors | $266.40 | 428 | ★ 3.0 | 97 | SKU-001022 |
| 1023 | Elite Toys & Games Product Special Edition | Toys & Games | $645.19 | 172 | ★ 2.6 | 970 | SKU-001023 |
| 1025 | Mega Home & Garden Product Advanced | Home & Garden | $240.08 | 209 | ★ 2.7 | 258 | SKU-001025 |
| 1027 | Elite Health & Beauty Product Plus | Health & Beauty | $37.70 | 104 | ★ 3.6 | 764 | SKU-001027 |
| 1028 | Ultra Food & Grocery Product XL | Food & Grocery | $107.16 | 437 | ★ 2.4 | 153 | SKU-001028 |
| 1029 | Deluxe Books Product Pro | Books | $199.95 | 425 | ★ 2.4 | 64 | SKU-001029 |
| 1032 | Premium Food & Grocery Product Mini | Food & Grocery | $147.32 | 29 | ★ 4.8 | 121 | SKU-001032 |
| 1034 | Economy Home & Garden Product Special Edition | Home & Garden | $703.11 | 387 | ★ 3.8 | 319 | SKU-001034 |
| 1035 | Super Health & Beauty Product Max | Health & Beauty | $307.22 | 300 | ★ 4.7 | 534 | SKU-001035 |
| 1036 | Deluxe Toys & Games Product Advanced | Toys & Games | $962.05 | 481 | ★ 1.8 | 604 | SKU-001036 |
| 1037 | Ultra Electronics Product Classic | Electronics | $499.36 | 50 | ★ 4.0 | 791 | SKU-001037 |
| 1038 | Elite Health & Beauty Product Mini | Health & Beauty | $890.33 | 237 | ★ 4.5 | 702 | SKU-001038 |
| 1039 | Professional Automotive Product Lite | Automotive | $985.93 | 322 | ★ 2.9 | 763 | SKU-001039 |
| 1040 | Pro Home & Garden Product Special Edition | Home & Garden | $834.34 | 27 | ★ 3.3 | 157 | SKU-001040 |
// 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
};
}