Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3193 | Standard Electronics Product Lite | Electronics | $659.93 | 383 | ★ 4.3 | 381 | SKU-003193 |
| 3194 | Ultra Electronics Product Lite | Electronics | $913.01 | 244 | ★ 3.8 | 856 | SKU-003194 |
| 3195 | Pro Food & Grocery Product XL | Food & Grocery | $327.33 | 349 | ★ 2.9 | 920 | SKU-003195 |
| 3196 | Elite Automotive Product Advanced | Automotive | $287.45 | 427 | ★ 1.9 | 999 | SKU-003196 |
| 3197 | Ultra Toys & Games Product Lite | Toys & Games | $855.91 | 335 | ★ 1.9 | 785 | SKU-003197 |
| 3198 | Super Health & Beauty Product XL | Health & Beauty | $714.10 | 432 | ★ 3.9 | 969 | SKU-003198 |
| 3199 | Standard Clothing Product Special Edition | Clothing | $812.44 | 422 | ★ 3.6 | 891 | SKU-003199 |
| 3200 | Professional Health & Beauty Product Mini | Health & Beauty | $739.82 | 296 | ★ 4.8 | 92 | SKU-003200 |
| 3201 | Professional Automotive Product Pro | Automotive | $232.77 | 473 | ★ 4.6 | 49 | SKU-003201 |
| 3203 | Elite Sports & Outdoors Product 2024 | Sports & Outdoors | $265.69 | 277 | ★ 1.7 | 38 | SKU-003203 |
| 3204 | Economy Sports & Outdoors Product Special Edition | Sports & Outdoors | $452.31 | 290 | ★ 4.9 | 86 | SKU-003204 |
| 3205 | Standard Electronics Product 2024 | Electronics | $686.87 | 404 | ★ 2.6 | 265 | SKU-003205 |
| 3206 | Professional Office Supplies Product Lite | Office Supplies | $55.01 | 479 | ★ 2.4 | 702 | SKU-003206 |
| 3207 | Deluxe Clothing Product Max | Clothing | $83.48 | 13 | ★ 1.7 | 757 | SKU-003207 |
| 3208 | Deluxe Clothing Product Mini | Clothing | $52.70 | 236 | ★ 4.8 | 951 | SKU-003208 |
| 3209 | Pro Automotive Product Mini | Automotive | $663.35 | 481 | ★ 4.7 | 98 | SKU-003209 |
| 3210 | Pro Office Supplies Product 2024 | Office Supplies | $439.82 | 296 | ★ 3.1 | 870 | SKU-003210 |
| 3211 | Pro Toys & Games Product 2024 | Toys & Games | $204.90 | 107 | ★ 3.5 | 495 | SKU-003211 |
| 3212 | Premium Books Product Plus | Books | $489.08 | 306 | ★ 3.6 | 70 | SKU-003212 |
| 3213 | Standard Health & Beauty Product Pro | Health & Beauty | $832.22 | 173 | ★ 3.5 | 901 | SKU-003213 |
| 3214 | Mega Sports & Outdoors Product Mini | Sports & Outdoors | $752.59 | 249 | ★ 2.6 | 642 | SKU-003214 |
| 3215 | Professional Electronics Product Special Edition | Electronics | $984.84 | 99 | ★ 2.7 | 748 | SKU-003215 |
| 3217 | Standard Clothing Product XL | Clothing | $534.28 | 384 | ★ 1.8 | 915 | SKU-003217 |
| 3218 | Economy Sports & Outdoors Product Lite | Sports & Outdoors | $486.87 | 113 | ★ 5.0 | 486 | SKU-003218 |
| 3220 | Pro Toys & Games Product Plus | Toys & Games | $578.93 | 171 | ★ 3.2 | 703 | SKU-003220 |
// 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
};
}