Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 477 | Deluxe Home & Garden Product XL | Home & Garden | $484.71 | 160 | ★ 4.9 | 30 | SKU-000477 |
| 478 | Ultra Sports & Outdoors Product Special Edition | Sports & Outdoors | $733.98 | 383 | ★ 2.1 | 150 | SKU-000478 |
| 479 | Ultra Clothing Product Special Edition | Clothing | $389.33 | 186 | ★ 3.6 | 232 | SKU-000479 |
| 480 | Premium Toys & Games Product Advanced | Toys & Games | $102.55 | 390 | ★ 4.0 | 182 | SKU-000480 |
| 481 | Pro Automotive Product Mini | Automotive | $969.07 | 497 | ★ 2.4 | 293 | SKU-000481 |
| 482 | Mega Electronics Product Plus | Electronics | $56.54 | 376 | ★ 4.7 | 217 | SKU-000482 |
| 483 | Standard Food & Grocery Product Special Edition | Food & Grocery | $103.47 | 388 | ★ 1.5 | 283 | SKU-000483 |
| 484 | Professional Sports & Outdoors Product 2024 | Sports & Outdoors | $563.71 | 43 | ★ 3.2 | 779 | SKU-000484 |
| 485 | Super Sports & Outdoors Product Lite | Sports & Outdoors | $426.26 | 473 | ★ 2.4 | 762 | SKU-000485 |
| 486 | Super Toys & Games Product Classic | Toys & Games | $621.60 | 225 | ★ 1.3 | 261 | SKU-000486 |
| 488 | Standard Sports & Outdoors Product Pro | Sports & Outdoors | $546.60 | 310 | ★ 4.0 | 485 | SKU-000488 |
| 489 | Premium Food & Grocery Product 2024 | Food & Grocery | $217.57 | 31 | ★ 1.0 | 57 | SKU-000489 |
| 490 | Pro Books Product XL | Books | $903.70 | 258 | ★ 3.8 | 577 | SKU-000490 |
| 491 | Ultra Office Supplies Product Max | Office Supplies | $553.61 | 371 | ★ 2.4 | 275 | SKU-000491 |
| 492 | Elite Toys & Games Product Max | Toys & Games | $645.79 | 247 | ★ 3.4 | 801 | SKU-000492 |
| 493 | Deluxe Automotive Product Advanced | Automotive | $866.01 | 8 | ★ 1.9 | 820 | SKU-000493 |
| 494 | Standard Electronics Product Special Edition | Electronics | $145.78 | 306 | ★ 4.4 | 660 | SKU-000494 |
| 495 | Elite Clothing Product XL | Clothing | $883.14 | 36 | ★ 2.6 | 10 | SKU-000495 |
| 496 | Premium Automotive Product Advanced | Automotive | $155.99 | 497 | ★ 2.3 | 658 | SKU-000496 |
| 497 | Premium Sports & Outdoors Product Plus | Sports & Outdoors | $318.57 | 155 | ★ 1.8 | 178 | SKU-000497 |
| 498 | Deluxe Sports & Outdoors Product Advanced | Sports & Outdoors | $209.03 | 251 | ★ 1.0 | 667 | SKU-000498 |
| 499 | Premium Home & Garden Product Advanced | Home & Garden | $31.31 | 329 | ★ 4.1 | 11 | SKU-000499 |
| 500 | Professional Food & Grocery Product Pro | Food & Grocery | $202.85 | 131 | ★ 2.1 | 998 | SKU-000500 |
| 501 | Super Toys & Games Product Special Edition | Toys & Games | $959.88 | 430 | ★ 4.6 | 130 | SKU-000501 |
| 502 | Pro Toys & Games Product Lite | Toys & Games | $837.04 | 166 | ★ 4.5 | 283 | SKU-000502 |
// 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
};
}