Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2529 | Economy Automotive Product XL | Automotive | $425.52 | 489 | ★ 4.0 | 476 | SKU-002529 |
| 2530 | Deluxe Toys & Games Product XL | Toys & Games | $257.43 | 320 | ★ 2.0 | 459 | SKU-002530 |
| 2531 | Deluxe Toys & Games Product Advanced | Toys & Games | $724.76 | 475 | ★ 3.2 | 344 | SKU-002531 |
| 2532 | Super Home & Garden Product Plus | Home & Garden | $120.90 | 421 | ★ 1.5 | 939 | SKU-002532 |
| 2533 | Elite Books Product Lite | Books | $649.81 | 331 | ★ 2.9 | 85 | SKU-002533 |
| 2534 | Economy Office Supplies Product Pro | Office Supplies | $530.71 | 133 | ★ 1.9 | 569 | SKU-002534 |
| 2535 | Deluxe Health & Beauty Product Plus | Health & Beauty | $536.89 | 153 | ★ 1.5 | 399 | SKU-002535 |
| 2537 | Standard Automotive Product Mini | Automotive | $317.33 | 204 | ★ 1.8 | 498 | SKU-002537 |
| 2538 | Premium Books Product 2024 | Books | $221.56 | 445 | ★ 3.0 | 335 | SKU-002538 |
| 2540 | Premium Electronics Product Special Edition | Electronics | $782.84 | 349 | ★ 3.8 | 587 | SKU-002540 |
| 2541 | Mega Electronics Product Plus | Electronics | $677.89 | 7 | ★ 2.8 | 631 | SKU-002541 |
| 2542 | Elite Health & Beauty Product Advanced | Health & Beauty | $330.25 | 310 | ★ 1.5 | 779 | SKU-002542 |
| 2543 | Pro Toys & Games Product Advanced | Toys & Games | $47.47 | 301 | ★ 1.9 | 10 | SKU-002543 |
| 2544 | Deluxe Automotive Product Max | Automotive | $789.90 | 324 | ★ 4.2 | 210 | SKU-002544 |
| 2545 | Economy Clothing Product Special Edition | Clothing | $633.96 | 162 | ★ 3.4 | 786 | SKU-002545 |
| 2547 | Premium Toys & Games Product Max | Toys & Games | $536.12 | 445 | ★ 3.4 | 155 | SKU-002547 |
| 2548 | Mega Home & Garden Product Lite | Home & Garden | $723.68 | 13 | ★ 2.7 | 791 | SKU-002548 |
| 2549 | Premium Automotive Product Special Edition | Automotive | $592.57 | 56 | ★ 1.8 | 6 | SKU-002549 |
| 2550 | Deluxe Food & Grocery Product XL | Food & Grocery | $341.47 | 328 | ★ 1.7 | 510 | SKU-002550 |
| 2551 | Premium Electronics Product Pro | Electronics | $289.28 | 269 | ★ 4.5 | 88 | SKU-002551 |
| 2552 | Elite Toys & Games Product Mini | Toys & Games | $790.67 | 13 | ★ 4.3 | 589 | SKU-002552 |
| 2553 | Mega Sports & Outdoors Product Lite | Sports & Outdoors | $925.28 | 119 | ★ 4.4 | 393 | SKU-002553 |
| 2555 | Standard Food & Grocery Product Special Edition | Food & Grocery | $57.55 | 49 | ★ 4.8 | 688 | SKU-002555 |
| 2556 | Professional Office Supplies Product Mini | Office Supplies | $779.42 | 472 | ★ 2.1 | 58 | SKU-002556 |
| 2557 | Premium Office Supplies Product Pro | Office Supplies | $873.80 | 230 | ★ 2.4 | 882 | SKU-002557 |
// 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
};
}