Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3111 | Deluxe Home & Garden Product Classic | Home & Garden | $499.92 | 120 | ★ 1.3 | 673 | SKU-003111 |
| 3112 | Ultra Books Product Pro | Books | $408.75 | 263 | ★ 4.7 | 631 | SKU-003112 |
| 3113 | Standard Home & Garden Product Special Edition | Home & Garden | $364.54 | 218 | ★ 2.0 | 499 | SKU-003113 |
| 3114 | Elite Clothing Product Plus | Clothing | $205.11 | 135 | ★ 3.3 | 522 | SKU-003114 |
| 3115 | Super Automotive Product Plus | Automotive | $960.32 | 92 | ★ 3.5 | 459 | SKU-003115 |
| 3116 | Premium Electronics Product Classic | Electronics | $290.00 | 279 | ★ 3.4 | 422 | SKU-003116 |
| 3117 | Ultra Health & Beauty Product 2024 | Health & Beauty | $792.64 | 341 | ★ 2.2 | 301 | SKU-003117 |
| 3118 | Premium Electronics Product Special Edition | Electronics | $233.76 | 121 | ★ 4.7 | 101 | SKU-003118 |
| 3119 | Elite Clothing Product Mini | Clothing | $405.48 | 119 | ★ 2.5 | 607 | SKU-003119 |
| 3120 | Premium Sports & Outdoors Product Special Edition | Sports & Outdoors | $410.55 | 235 | ★ 3.5 | 302 | SKU-003120 |
| 3121 | Elite Automotive Product Mini | Automotive | $861.89 | 450 | ★ 2.4 | 322 | SKU-003121 |
| 3122 | Premium Automotive Product Advanced | Automotive | $165.93 | 159 | ★ 1.5 | 387 | SKU-003122 |
| 3123 | Premium Health & Beauty Product Mini | Health & Beauty | $927.96 | 483 | ★ 2.6 | 51 | SKU-003123 |
| 3124 | Super Toys & Games Product Lite | Toys & Games | $629.27 | 5 | ★ 1.5 | 355 | SKU-003124 |
| 3125 | Mega Office Supplies Product Classic | Office Supplies | $662.30 | 488 | ★ 1.3 | 283 | SKU-003125 |
| 3127 | Economy Food & Grocery Product Plus | Food & Grocery | $472.15 | 464 | ★ 2.9 | 694 | SKU-003127 |
| 3128 | Ultra Health & Beauty Product 2024 | Health & Beauty | $262.13 | 313 | ★ 3.8 | 716 | SKU-003128 |
| 3129 | Standard Health & Beauty Product Mini | Health & Beauty | $523.80 | 89 | ★ 4.6 | 562 | SKU-003129 |
| 3130 | Standard Toys & Games Product Plus | Toys & Games | $114.58 | 371 | ★ 2.8 | 726 | SKU-003130 |
| 3131 | Super Health & Beauty Product Lite | Health & Beauty | $449.81 | 209 | ★ 4.7 | 847 | SKU-003131 |
| 3132 | Premium Clothing Product Lite | Clothing | $571.50 | 304 | ★ 1.4 | 241 | SKU-003132 |
| 3133 | Premium Sports & Outdoors Product Lite | Sports & Outdoors | $745.32 | 375 | ★ 2.1 | 134 | SKU-003133 |
| 3134 | Mega Automotive Product Pro | Automotive | $388.29 | 196 | ★ 3.0 | 734 | SKU-003134 |
| 3135 | Super Books Product 2024 | Books | $722.51 | 160 | ★ 2.0 | 59 | SKU-003135 |
| 3136 | Economy Office Supplies Product Plus | Office Supplies | $566.30 | 138 | ★ 4.7 | 908 | SKU-003136 |
// 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
};
}