Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 3163 | Economy Office Supplies Product Plus | Office Supplies | $24.19 | 66 | ★ 3.2 | 682 | SKU-003163 |
| 3164 | Super Clothing Product Lite | Clothing | $537.36 | 221 | ★ 2.3 | 590 | SKU-003164 |
| 3165 | Standard Automotive Product Mini | Automotive | $755.72 | 474 | ★ 2.5 | 561 | SKU-003165 |
| 3166 | Mega Food & Grocery Product XL | Food & Grocery | $41.48 | 42 | ★ 1.1 | 69 | SKU-003166 |
| 3168 | Mega Office Supplies Product Advanced | Office Supplies | $525.35 | 290 | ★ 1.3 | 15 | SKU-003168 |
| 3169 | Premium Automotive Product Max | Automotive | $539.95 | 465 | ★ 1.7 | 511 | SKU-003169 |
| 3171 | Economy Health & Beauty Product Advanced | Health & Beauty | $510.65 | 220 | ★ 4.9 | 996 | SKU-003171 |
| 3172 | Ultra Health & Beauty Product Pro | Health & Beauty | $605.06 | 58 | ★ 1.9 | 748 | SKU-003172 |
| 3173 | Standard Clothing Product Mini | Clothing | $526.00 | 158 | ★ 1.5 | 734 | SKU-003173 |
| 3174 | Standard Sports & Outdoors Product Plus | Sports & Outdoors | $54.27 | 435 | ★ 2.2 | 686 | SKU-003174 |
| 3175 | Pro Toys & Games Product Special Edition | Toys & Games | $854.95 | 133 | ★ 1.3 | 569 | SKU-003175 |
| 3176 | Pro Clothing Product Advanced | Clothing | $93.44 | 265 | ★ 3.8 | 232 | SKU-003176 |
| 3177 | Pro Electronics Product Max | Electronics | $375.04 | 442 | ★ 2.2 | 810 | SKU-003177 |
| 3178 | Mega Clothing Product Plus | Clothing | $394.64 | 258 | ★ 4.4 | 355 | SKU-003178 |
| 3179 | Mega Books Product XL | Books | $338.31 | 262 | ★ 4.9 | 425 | SKU-003179 |
| 3181 | Elite Office Supplies Product 2024 | Office Supplies | $937.63 | 318 | ★ 1.7 | 351 | SKU-003181 |
| 3182 | Pro Home & Garden Product 2024 | Home & Garden | $677.76 | 221 | ★ 1.2 | 342 | SKU-003182 |
| 3183 | Deluxe Office Supplies Product Plus | Office Supplies | $202.10 | 11 | ★ 4.8 | 233 | SKU-003183 |
| 3184 | Super Sports & Outdoors Product Max | Sports & Outdoors | $31.08 | 445 | ★ 4.6 | 924 | SKU-003184 |
| 3185 | Ultra Electronics Product Plus | Electronics | $390.77 | 362 | ★ 2.5 | 49 | SKU-003185 |
| 3186 | Economy Electronics Product Max | Electronics | $81.20 | 94 | ★ 4.5 | 939 | SKU-003186 |
| 3187 | Super Automotive Product 2024 | Automotive | $570.45 | 200 | ★ 4.8 | 410 | SKU-003187 |
| 3188 | Super Sports & Outdoors Product XL | Sports & Outdoors | $513.43 | 37 | ★ 1.8 | 886 | SKU-003188 |
| 3190 | Economy Books Product Pro | Books | $714.65 | 331 | ★ 3.5 | 168 | SKU-003190 |
| 3192 | Standard Automotive Product Mini | Automotive | $534.58 | 291 | ★ 4.2 | 407 | SKU-003192 |
// 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
};
}