Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3341 | Pro Office Supplies Product 2024 | Office Supplies | $805.62 | 296 | ★ 3.6 | 983 | SKU-003341 |
| 3342 | Ultra Home & Garden Product Max | Home & Garden | $209.08 | 98 | ★ 4.2 | 798 | SKU-003342 |
| 3343 | Mega Home & Garden Product Advanced | Home & Garden | $822.85 | 480 | ★ 2.8 | 400 | SKU-003343 |
| 3344 | Economy Health & Beauty Product 2024 | Health & Beauty | $838.50 | 97 | ★ 1.1 | 755 | SKU-003344 |
| 3345 | Deluxe Automotive Product Advanced | Automotive | $216.35 | 489 | ★ 1.5 | 760 | SKU-003345 |
| 3346 | Economy Office Supplies Product 2024 | Office Supplies | $967.29 | 447 | ★ 2.3 | 578 | SKU-003346 |
| 3347 | Deluxe Health & Beauty Product Advanced | Health & Beauty | $117.89 | 174 | ★ 4.9 | 660 | SKU-003347 |
| 3348 | Pro Office Supplies Product Advanced | Office Supplies | $108.94 | 359 | ★ 3.3 | 194 | SKU-003348 |
| 3349 | Mega Automotive Product Max | Automotive | $190.03 | 35 | ★ 2.0 | 694 | SKU-003349 |
| 3350 | Professional Books Product Max | Books | $143.08 | 312 | ★ 2.3 | 371 | SKU-003350 |
| 3351 | Pro Home & Garden Product Special Edition | Home & Garden | $782.92 | 191 | ★ 3.3 | 214 | SKU-003351 |
| 3352 | Mega Office Supplies Product Advanced | Office Supplies | $296.48 | 38 | ★ 3.3 | 520 | SKU-003352 |
| 3353 | Ultra Food & Grocery Product Lite | Food & Grocery | $793.21 | 14 | ★ 2.2 | 601 | SKU-003353 |
| 3354 | Elite Books Product Max | Books | $746.70 | 29 | ★ 4.4 | 680 | SKU-003354 |
| 3355 | Premium Books Product 2024 | Books | $681.00 | 447 | ★ 4.4 | 350 | SKU-003355 |
| 3356 | Ultra Office Supplies Product Max | Office Supplies | $919.03 | 329 | ★ 4.3 | 524 | SKU-003356 |
| 3357 | Ultra Books Product Plus | Books | $529.08 | 418 | ★ 1.4 | 228 | SKU-003357 |
| 3358 | Mega Automotive Product Lite | Automotive | $849.29 | 109 | ★ 1.3 | 321 | SKU-003358 |
| 3360 | Mega Automotive Product Plus | Automotive | $309.44 | 310 | ★ 5.0 | 802 | SKU-003360 |
| 3361 | Professional Home & Garden Product Advanced | Home & Garden | $795.36 | 142 | ★ 1.1 | 110 | SKU-003361 |
| 3362 | Pro Electronics Product Classic | Electronics | $567.72 | 113 | ★ 3.7 | 531 | SKU-003362 |
| 3363 | Mega Food & Grocery Product Mini | Food & Grocery | $478.48 | 208 | ★ 3.4 | 715 | SKU-003363 |
| 3364 | Deluxe Food & Grocery Product Lite | Food & Grocery | $486.87 | 237 | ★ 1.4 | 234 | SKU-003364 |
| 3365 | Pro Automotive Product Lite | Automotive | $838.41 | 369 | ★ 2.5 | 909 | SKU-003365 |
| 3366 | Pro Automotive Product 2024 | Automotive | $37.83 | 103 | ★ 2.1 | 183 | SKU-003366 |
// 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
};
}