Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2751 | Standard Clothing Product Advanced | Clothing | $348.89 | 418 | ★ 2.4 | 185 | SKU-002751 |
| 2752 | Elite Electronics Product Lite | Electronics | $766.08 | 339 | ★ 2.6 | 699 | SKU-002752 |
| 2753 | Super Clothing Product Plus | Clothing | $580.87 | 64 | ★ 4.2 | 573 | SKU-002753 |
| 2754 | Deluxe Office Supplies Product Advanced | Office Supplies | $881.28 | 392 | ★ 2.1 | 75 | SKU-002754 |
| 2755 | Elite Sports & Outdoors Product Max | Sports & Outdoors | $188.38 | 82 | ★ 1.4 | 550 | SKU-002755 |
| 2756 | Elite Home & Garden Product 2024 | Home & Garden | $997.53 | 47 | ★ 1.7 | 253 | SKU-002756 |
| 2757 | Standard Sports & Outdoors Product Lite | Sports & Outdoors | $561.45 | 401 | ★ 1.9 | 307 | SKU-002757 |
| 2758 | Super Books Product 2024 | Books | $929.16 | 9 | ★ 2.5 | 282 | SKU-002758 |
| 2759 | Professional Automotive Product Advanced | Automotive | $133.27 | 334 | ★ 3.6 | 745 | SKU-002759 |
| 2760 | Deluxe Books Product Advanced | Books | $947.48 | 191 | ★ 1.2 | 795 | SKU-002760 |
| 2761 | Pro Clothing Product 2024 | Clothing | $566.63 | 490 | ★ 3.3 | 87 | SKU-002761 |
| 2762 | Premium Electronics Product Plus | Electronics | $768.86 | 418 | ★ 3.2 | 201 | SKU-002762 |
| 2763 | Professional Automotive Product XL | Automotive | $339.61 | 239 | ★ 3.5 | 78 | SKU-002763 |
| 2764 | Pro Office Supplies Product Lite | Office Supplies | $589.47 | 462 | ★ 1.8 | 860 | SKU-002764 |
| 2765 | Ultra Health & Beauty Product XL | Health & Beauty | $217.55 | 458 | ★ 2.1 | 191 | SKU-002765 |
| 2767 | Pro Health & Beauty Product Classic | Health & Beauty | $832.24 | 53 | ★ 4.4 | 652 | SKU-002767 |
| 2768 | Premium Health & Beauty Product Lite | Health & Beauty | $599.85 | 110 | ★ 1.3 | 808 | SKU-002768 |
| 2769 | Elite Health & Beauty Product 2024 | Health & Beauty | $644.65 | 95 | ★ 3.0 | 779 | SKU-002769 |
| 2770 | Deluxe Food & Grocery Product Special Edition | Food & Grocery | $567.99 | 216 | ★ 1.5 | 589 | SKU-002770 |
| 2771 | Standard Home & Garden Product Classic | Home & Garden | $485.96 | 31 | ★ 2.4 | 920 | SKU-002771 |
| 2773 | Elite Home & Garden Product XL | Home & Garden | $448.95 | 276 | ★ 3.2 | 944 | SKU-002773 |
| 2774 | Premium Toys & Games Product Max | Toys & Games | $611.87 | 165 | ★ 3.8 | 977 | SKU-002774 |
| 2775 | Mega Toys & Games Product Advanced | Toys & Games | $157.72 | 310 | ★ 1.3 | 487 | SKU-002775 |
| 2777 | Ultra Sports & Outdoors Product Classic | Sports & Outdoors | $696.08 | 33 | ★ 2.0 | 278 | SKU-002777 |
| 2778 | Premium Office Supplies Product XL | Office Supplies | $75.94 | 171 | ★ 3.5 | 905 | SKU-002778 |
// 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
};
}