Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3221 | Pro Automotive Product Lite | Automotive | $506.48 | 455 | ★ 2.9 | 75 | SKU-003221 |
| 3222 | Deluxe Food & Grocery Product Lite | Food & Grocery | $785.32 | 485 | ★ 2.6 | 115 | SKU-003222 |
| 3223 | Standard Health & Beauty Product Classic | Health & Beauty | $839.43 | 24 | ★ 4.8 | 64 | SKU-003223 |
| 3224 | Standard Toys & Games Product Plus | Toys & Games | $605.89 | 73 | ★ 3.7 | 551 | SKU-003224 |
| 3225 | Super Sports & Outdoors Product Lite | Sports & Outdoors | $195.69 | 393 | ★ 4.8 | 497 | SKU-003225 |
| 3226 | Deluxe Books Product Classic | Books | $814.60 | 289 | ★ 4.8 | 198 | SKU-003226 |
| 3227 | Premium Health & Beauty Product XL | Health & Beauty | $770.60 | 386 | ★ 3.2 | 60 | SKU-003227 |
| 3228 | Super Health & Beauty Product Advanced | Health & Beauty | $258.59 | 100 | ★ 3.8 | 708 | SKU-003228 |
| 3229 | Economy Home & Garden Product 2024 | Home & Garden | $952.17 | 477 | ★ 4.0 | 890 | SKU-003229 |
| 3230 | Pro Health & Beauty Product Advanced | Health & Beauty | $43.57 | 19 | ★ 1.6 | 415 | SKU-003230 |
| 3231 | Mega Electronics Product XL | Electronics | $458.30 | 228 | ★ 2.6 | 598 | SKU-003231 |
| 3232 | Deluxe Home & Garden Product Plus | Home & Garden | $126.34 | 498 | ★ 3.6 | 956 | SKU-003232 |
| 3234 | Ultra Automotive Product Mini | Automotive | $223.61 | 345 | ★ 1.6 | 626 | SKU-003234 |
| 3235 | Premium Sports & Outdoors Product Special Edition | Sports & Outdoors | $221.94 | 256 | ★ 2.6 | 859 | SKU-003235 |
| 3237 | Elite Office Supplies Product 2024 | Office Supplies | $993.73 | 462 | ★ 3.8 | 323 | SKU-003237 |
| 3238 | Mega Electronics Product Classic | Electronics | $493.55 | 324 | ★ 3.2 | 609 | SKU-003238 |
| 3239 | Super Food & Grocery Product Plus | Food & Grocery | $755.37 | 245 | ★ 2.2 | 994 | SKU-003239 |
| 3240 | Standard Clothing Product XL | Clothing | $373.29 | 9 | ★ 2.3 | 478 | SKU-003240 |
| 3241 | Premium Automotive Product Special Edition | Automotive | $570.31 | 149 | ★ 1.9 | 190 | SKU-003241 |
| 3242 | Standard Office Supplies Product 2024 | Office Supplies | $451.58 | 447 | ★ 2.2 | 421 | SKU-003242 |
| 3243 | Standard Automotive Product Classic | Automotive | $954.37 | 347 | ★ 4.3 | 146 | SKU-003243 |
| 3244 | Standard Clothing Product Special Edition | Clothing | $652.25 | 7 | ★ 3.9 | 310 | SKU-003244 |
| 3245 | Ultra Automotive Product Mini | Automotive | $995.01 | 401 | ★ 4.0 | 517 | SKU-003245 |
| 3246 | Premium Electronics Product Max | Electronics | $358.43 | 232 | ★ 2.0 | 882 | SKU-003246 |
| 3249 | Economy Sports & Outdoors Product Plus | Sports & Outdoors | $140.62 | 242 | ★ 1.3 | 334 | SKU-003249 |
// 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
};
}