Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2393 | Ultra Food & Grocery Product 2024 | Food & Grocery | $116.35 | 81 | ★ 1.8 | 836 | SKU-002393 |
| 2394 | Mega Automotive Product 2024 | Automotive | $611.71 | 35 | ★ 2.0 | 141 | SKU-002394 |
| 2395 | Elite Office Supplies Product Max | Office Supplies | $912.51 | 32 | ★ 1.4 | 473 | SKU-002395 |
| 2396 | Ultra Clothing Product Pro | Clothing | $590.14 | 29 | ★ 3.0 | 143 | SKU-002396 |
| 2398 | Super Sports & Outdoors Product Advanced | Sports & Outdoors | $130.38 | 308 | ★ 1.9 | 320 | SKU-002398 |
| 2399 | Economy Electronics Product Classic | Electronics | $963.02 | 134 | ★ 2.5 | 729 | SKU-002399 |
| 2400 | Elite Home & Garden Product XL | Home & Garden | $917.43 | 441 | ★ 4.7 | 52 | SKU-002400 |
| 2401 | Deluxe Office Supplies Product Lite | Office Supplies | $249.97 | 83 | ★ 4.9 | 276 | SKU-002401 |
| 2402 | Professional Automotive Product Mini | Automotive | $700.11 | 439 | ★ 3.3 | 656 | SKU-002402 |
| 2403 | Ultra Electronics Product Lite | Electronics | $851.58 | 307 | ★ 2.1 | 64 | SKU-002403 |
| 2404 | Ultra Health & Beauty Product Max | Health & Beauty | $261.02 | 31 | ★ 3.9 | 353 | SKU-002404 |
| 2405 | Standard Electronics Product Plus | Electronics | $551.87 | 281 | ★ 3.2 | 35 | SKU-002405 |
| 2407 | Economy Clothing Product Advanced | Clothing | $513.02 | 4 | ★ 4.6 | 370 | SKU-002407 |
| 2408 | Mega Sports & Outdoors Product Classic | Sports & Outdoors | $994.18 | 354 | ★ 2.8 | 182 | SKU-002408 |
| 2409 | Premium Automotive Product XL | Automotive | $908.17 | 249 | ★ 1.2 | 272 | SKU-002409 |
| 2410 | Elite Home & Garden Product Max | Home & Garden | $962.29 | 172 | ★ 4.1 | 589 | SKU-002410 |
| 2411 | Ultra Toys & Games Product Plus | Toys & Games | $559.15 | 410 | ★ 1.4 | 371 | SKU-002411 |
| 2412 | Elite Clothing Product Special Edition | Clothing | $361.16 | 459 | ★ 2.6 | 129 | SKU-002412 |
| 2413 | Super Home & Garden Product XL | Home & Garden | $945.12 | 176 | ★ 4.5 | 808 | SKU-002413 |
| 2414 | Premium Toys & Games Product Special Edition | Toys & Games | $486.54 | 423 | ★ 3.9 | 358 | SKU-002414 |
| 2415 | Elite Books Product Special Edition | Books | $901.73 | 420 | ★ 4.0 | 210 | SKU-002415 |
| 2416 | Deluxe Health & Beauty Product Special Edition | Health & Beauty | $729.83 | 485 | ★ 3.4 | 732 | SKU-002416 |
| 2417 | Standard Automotive Product XL | Automotive | $429.32 | 176 | ★ 1.5 | 904 | SKU-002417 |
| 2418 | Super Electronics Product Mini | Electronics | $697.03 | 375 | ★ 4.2 | 991 | SKU-002418 |
| 2419 | Elite Electronics Product Lite | Electronics | $527.59 | 204 | ★ 4.5 | 795 | SKU-002419 |
// 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
};
}