Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1186 | Super Automotive Product Lite | Automotive | $882.04 | 45 | ★ 3.4 | 394 | SKU-001186 |
| 1188 | Professional Sports & Outdoors Product Mini | Sports & Outdoors | $819.13 | 121 | ★ 1.4 | 723 | SKU-001188 |
| 1189 | Elite Clothing Product Max | Clothing | $129.65 | 323 | ★ 2.1 | 695 | SKU-001189 |
| 1190 | Mega Home & Garden Product Classic | Home & Garden | $453.60 | 311 | ★ 2.2 | 475 | SKU-001190 |
| 1191 | Pro Food & Grocery Product Advanced | Food & Grocery | $121.00 | 182 | ★ 1.0 | 225 | SKU-001191 |
| 1192 | Economy Toys & Games Product 2024 | Toys & Games | $264.31 | 443 | ★ 4.6 | 931 | SKU-001192 |
| 1193 | Deluxe Automotive Product Special Edition | Automotive | $52.08 | 158 | ★ 3.3 | 392 | SKU-001193 |
| 1194 | Standard Toys & Games Product Advanced | Toys & Games | $267.26 | 69 | ★ 3.6 | 900 | SKU-001194 |
| 1195 | Economy Automotive Product 2024 | Automotive | $821.98 | 1 | ★ 1.7 | 158 | SKU-001195 |
| 1196 | Ultra Office Supplies Product Plus | Office Supplies | $323.55 | 371 | ★ 4.8 | 479 | SKU-001196 |
| 1197 | Elite Clothing Product Max | Clothing | $918.46 | 345 | ★ 2.8 | 802 | SKU-001197 |
| 1199 | Premium Clothing Product Mini | Clothing | $644.90 | 20 | ★ 3.7 | 62 | SKU-001199 |
| 1201 | Premium Health & Beauty Product Special Edition | Health & Beauty | $144.16 | 61 | ★ 2.9 | 922 | SKU-001201 |
| 1202 | Deluxe Electronics Product Pro | Electronics | $294.63 | 397 | ★ 1.7 | 205 | SKU-001202 |
| 1203 | Elite Automotive Product Mini | Automotive | $691.83 | 11 | ★ 3.7 | 249 | SKU-001203 |
| 1204 | Premium Sports & Outdoors Product Plus | Sports & Outdoors | $937.15 | 242 | ★ 2.8 | 462 | SKU-001204 |
| 1205 | Deluxe Books Product Special Edition | Books | $481.34 | 325 | ★ 1.7 | 994 | SKU-001205 |
| 1206 | Pro Sports & Outdoors Product Special Edition | Sports & Outdoors | $227.82 | 313 | ★ 3.6 | 258 | SKU-001206 |
| 1207 | Professional Books Product Mini | Books | $547.33 | 392 | ★ 4.1 | 541 | SKU-001207 |
| 1210 | Standard Sports & Outdoors Product 2024 | Sports & Outdoors | $99.35 | 416 | ★ 3.6 | 728 | SKU-001210 |
| 1211 | Economy Food & Grocery Product Lite | Food & Grocery | $661.49 | 138 | ★ 3.4 | 367 | SKU-001211 |
| 1212 | Ultra Office Supplies Product Max | Office Supplies | $137.58 | 433 | ★ 1.5 | 577 | SKU-001212 |
| 1213 | Pro Electronics Product Advanced | Electronics | $857.31 | 24 | ★ 4.8 | 827 | SKU-001213 |
| 1215 | Super Books Product Classic | Books | $926.41 | 295 | ★ 2.1 | 812 | SKU-001215 |
| 1216 | Elite Books Product Pro | Books | $909.51 | 98 | ★ 3.2 | 305 | SKU-001216 |
// 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
};
}