Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2420 | Ultra Sports & Outdoors Product XL | Sports & Outdoors | $125.30 | 112 | ★ 2.5 | 931 | SKU-002420 |
| 2421 | Economy Electronics Product Special Edition | Electronics | $722.52 | 108 | ★ 3.2 | 542 | SKU-002421 |
| 2422 | Super Sports & Outdoors Product XL | Sports & Outdoors | $276.84 | 475 | ★ 4.5 | 303 | SKU-002422 |
| 2423 | Standard Food & Grocery Product Max | Food & Grocery | $959.24 | 248 | ★ 2.9 | 15 | SKU-002423 |
| 2424 | Ultra Clothing Product Pro | Clothing | $484.10 | 415 | ★ 1.2 | 490 | SKU-002424 |
| 2425 | Mega Toys & Games Product Plus | Toys & Games | $915.38 | 401 | ★ 1.6 | 506 | SKU-002425 |
| 2426 | Elite Books Product Plus | Books | $983.89 | 22 | ★ 4.5 | 415 | SKU-002426 |
| 2427 | Ultra Home & Garden Product Max | Home & Garden | $174.99 | 37 | ★ 2.2 | 173 | SKU-002427 |
| 2428 | Professional Food & Grocery Product Plus | Food & Grocery | $591.99 | 236 | ★ 2.5 | 400 | SKU-002428 |
| 2429 | Premium Home & Garden Product Max | Home & Garden | $180.20 | 207 | ★ 2.9 | 694 | SKU-002429 |
| 2431 | Super Toys & Games Product Plus | Toys & Games | $801.52 | 146 | ★ 2.0 | 122 | SKU-002431 |
| 2432 | Professional Books Product XL | Books | $412.91 | 207 | ★ 2.8 | 43 | SKU-002432 |
| 2433 | Super Toys & Games Product Lite | Toys & Games | $299.57 | 219 | ★ 2.3 | 801 | SKU-002433 |
| 2434 | Elite Electronics Product Advanced | Electronics | $928.19 | 270 | ★ 2.6 | 47 | SKU-002434 |
| 2435 | Standard Food & Grocery Product Pro | Food & Grocery | $811.81 | 58 | ★ 3.3 | 546 | SKU-002435 |
| 2436 | Ultra Office Supplies Product Mini | Office Supplies | $91.97 | 424 | ★ 2.5 | 295 | SKU-002436 |
| 2437 | Pro Clothing Product Special Edition | Clothing | $840.15 | 424 | ★ 2.3 | 659 | SKU-002437 |
| 2438 | Ultra Toys & Games Product Plus | Toys & Games | $607.50 | 342 | ★ 4.6 | 372 | SKU-002438 |
| 2439 | Professional Books Product XL | Books | $554.03 | 68 | ★ 4.5 | 994 | SKU-002439 |
| 2440 | Premium Office Supplies Product 2024 | Office Supplies | $989.44 | 60 | ★ 3.0 | 480 | SKU-002440 |
| 2441 | Mega Automotive Product Advanced | Automotive | $188.10 | 212 | ★ 4.9 | 716 | SKU-002441 |
| 2442 | Mega Clothing Product Max | Clothing | $603.53 | 193 | ★ 2.6 | 439 | SKU-002442 |
| 2443 | Mega Books Product Plus | Books | $432.23 | 21 | ★ 2.6 | 887 | SKU-002443 |
| 2444 | Elite Clothing Product Plus | Clothing | $299.83 | 327 | ★ 3.6 | 441 | SKU-002444 |
| 2446 | Deluxe Health & Beauty Product XL | Health & Beauty | $548.67 | 433 | ★ 4.7 | 765 | SKU-002446 |
// 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
};
}