Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 4448 | Standard Office Supplies Product 2024 | Office Supplies | $303.87 | 299 | ★ 3.1 | 916 | SKU-004448 |
| 4449 | Ultra Home & Garden Product Classic | Home & Garden | $857.23 | 273 | ★ 3.3 | 493 | SKU-004449 |
| 4450 | Premium Office Supplies Product Advanced | Office Supplies | $820.60 | 455 | ★ 4.4 | 597 | SKU-004450 |
| 4454 | Standard Sports & Outdoors Product Advanced | Sports & Outdoors | $281.68 | 230 | ★ 3.7 | 118 | SKU-004454 |
| 4455 | Pro Sports & Outdoors Product Pro | Sports & Outdoors | $196.57 | 382 | ★ 1.3 | 584 | SKU-004455 |
| 4456 | Economy Home & Garden Product 2024 | Home & Garden | $377.41 | 446 | ★ 4.6 | 885 | SKU-004456 |
| 4458 | Super Books Product Max | Books | $248.32 | 91 | ★ 4.4 | 90 | SKU-004458 |
| 4459 | Super Health & Beauty Product Classic | Health & Beauty | $202.51 | 129 | ★ 3.9 | 628 | SKU-004459 |
| 4460 | Super Food & Grocery Product XL | Food & Grocery | $920.72 | 124 | ★ 2.5 | 44 | SKU-004460 |
| 4461 | Premium Electronics Product Classic | Electronics | $373.89 | 478 | ★ 3.2 | 417 | SKU-004461 |
| 4462 | Elite Health & Beauty Product Pro | Health & Beauty | $895.20 | 498 | ★ 3.7 | 926 | SKU-004462 |
| 4464 | Deluxe Automotive Product Max | Automotive | $154.52 | 373 | ★ 1.8 | 183 | SKU-004464 |
| 4465 | Pro Home & Garden Product Classic | Home & Garden | $389.73 | 492 | ★ 1.2 | 549 | SKU-004465 |
| 4466 | Deluxe Office Supplies Product Lite | Office Supplies | $938.86 | 101 | ★ 4.5 | 375 | SKU-004466 |
| 4467 | Standard Books Product Pro | Books | $409.32 | 9 | ★ 4.8 | 262 | SKU-004467 |
| 4468 | Mega Office Supplies Product Special Edition | Office Supplies | $934.75 | 438 | ★ 1.4 | 55 | SKU-004468 |
| 4469 | Standard Toys & Games Product Pro | Toys & Games | $985.46 | 0 | ★ 1.7 | 305 | SKU-004469 |
| 4470 | Standard Electronics Product Advanced | Electronics | $837.73 | 49 | ★ 4.1 | 695 | SKU-004470 |
| 4471 | Deluxe Books Product Mini | Books | $573.18 | 135 | ★ 4.5 | 372 | SKU-004471 |
| 4472 | Standard Sports & Outdoors Product Mini | Sports & Outdoors | $878.70 | 291 | ★ 1.4 | 635 | SKU-004472 |
| 4473 | Deluxe Books Product Special Edition | Books | $949.59 | 178 | ★ 3.4 | 300 | SKU-004473 |
| 4474 | Mega Electronics Product XL | Electronics | $900.75 | 224 | ★ 2.8 | 946 | SKU-004474 |
| 4475 | Mega Clothing Product Advanced | Clothing | $744.30 | 451 | ★ 3.9 | 752 | SKU-004475 |
| 4477 | Pro Sports & Outdoors Product Special Edition | Sports & Outdoors | $485.92 | 131 | ★ 3.4 | 848 | SKU-004477 |
| 4478 | Mega Toys & Games Product Mini | Toys & Games | $26.84 | 290 | ★ 3.9 | 810 | SKU-004478 |
// 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
};
}