Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3367 | Ultra Clothing Product Max | Clothing | $210.00 | 276 | ★ 4.3 | 38 | SKU-003367 |
| 3368 | Ultra Electronics Product Special Edition | Electronics | $700.10 | 435 | ★ 4.1 | 476 | SKU-003368 |
| 3369 | Deluxe Home & Garden Product XL | Home & Garden | $13.16 | 193 | ★ 2.8 | 612 | SKU-003369 |
| 3370 | Pro Electronics Product Special Edition | Electronics | $973.64 | 360 | ★ 3.6 | 670 | SKU-003370 |
| 3371 | Ultra Electronics Product Plus | Electronics | $797.83 | 12 | ★ 4.3 | 434 | SKU-003371 |
| 3372 | Elite Electronics Product Lite | Electronics | $388.91 | 91 | ★ 1.7 | 555 | SKU-003372 |
| 3373 | Pro Food & Grocery Product Mini | Food & Grocery | $327.71 | 254 | ★ 1.7 | 575 | SKU-003373 |
| 3374 | Professional Toys & Games Product Plus | Toys & Games | $757.28 | 237 | ★ 4.6 | 34 | SKU-003374 |
| 3375 | Ultra Food & Grocery Product Lite | Food & Grocery | $835.62 | 153 | ★ 3.6 | 760 | SKU-003375 |
| 3376 | Ultra Health & Beauty Product 2024 | Health & Beauty | $828.74 | 378 | ★ 1.0 | 507 | SKU-003376 |
| 3377 | Premium Clothing Product Max | Clothing | $461.72 | 422 | ★ 5.0 | 513 | SKU-003377 |
| 3378 | Ultra Home & Garden Product Max | Home & Garden | $37.43 | 67 | ★ 4.5 | 276 | SKU-003378 |
| 3379 | Premium Books Product Special Edition | Books | $81.48 | 253 | ★ 2.8 | 251 | SKU-003379 |
| 3381 | Pro Toys & Games Product Plus | Toys & Games | $472.58 | 206 | ★ 3.9 | 73 | SKU-003381 |
| 3382 | Professional Health & Beauty Product Classic | Health & Beauty | $654.02 | 169 | ★ 3.2 | 862 | SKU-003382 |
| 3384 | Deluxe Health & Beauty Product Special Edition | Health & Beauty | $954.73 | 148 | ★ 4.6 | 459 | SKU-003384 |
| 3385 | Deluxe Home & Garden Product 2024 | Home & Garden | $31.50 | 298 | ★ 3.2 | 75 | SKU-003385 |
| 3386 | Professional Toys & Games Product Advanced | Toys & Games | $231.46 | 461 | ★ 4.5 | 717 | SKU-003386 |
| 3388 | Professional Books Product 2024 | Books | $79.17 | 342 | ★ 1.0 | 268 | SKU-003388 |
| 3389 | Elite Home & Garden Product Special Edition | Home & Garden | $676.62 | 317 | ★ 2.3 | 497 | SKU-003389 |
| 3390 | Mega Books Product 2024 | Books | $927.19 | 95 | ★ 1.7 | 218 | SKU-003390 |
| 3391 | Mega Food & Grocery Product Special Edition | Food & Grocery | $575.99 | 182 | ★ 1.1 | 719 | SKU-003391 |
| 3392 | Premium Books Product Mini | Books | $327.98 | 384 | ★ 2.0 | 420 | SKU-003392 |
| 3393 | Standard Home & Garden Product Plus | Home & Garden | $479.31 | 44 | ★ 2.7 | 781 | SKU-003393 |
| 3394 | Ultra Automotive Product Advanced | Automotive | $14.54 | 368 | ★ 1.2 | 415 | SKU-003394 |
// 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
};
}