Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1419 | Premium Office Supplies Product Special Edition | Office Supplies | $497.83 | 69 | ★ 3.0 | 379 | SKU-001419 |
| 1420 | Standard Books Product Special Edition | Books | $154.45 | 72 | ★ 4.0 | 648 | SKU-001420 |
| 1422 | Standard Electronics Product Pro | Electronics | $557.33 | 44 | ★ 2.0 | 289 | SKU-001422 |
| 1423 | Premium Automotive Product Max | Automotive | $652.13 | 358 | ★ 4.9 | 425 | SKU-001423 |
| 1424 | Professional Books Product 2024 | Books | $233.31 | 447 | ★ 3.5 | 87 | SKU-001424 |
| 1425 | Premium Food & Grocery Product Lite | Food & Grocery | $545.49 | 141 | ★ 3.8 | 620 | SKU-001425 |
| 1426 | Professional Home & Garden Product Lite | Home & Garden | $235.07 | 238 | ★ 4.3 | 350 | SKU-001426 |
| 1427 | Super Office Supplies Product Plus | Office Supplies | $977.81 | 41 | ★ 2.8 | 388 | SKU-001427 |
| 1428 | Super Health & Beauty Product Lite | Health & Beauty | $219.41 | 103 | ★ 1.1 | 636 | SKU-001428 |
| 1429 | Mega Office Supplies Product Max | Office Supplies | $510.74 | 116 | ★ 1.7 | 900 | SKU-001429 |
| 1430 | Professional Sports & Outdoors Product Plus | Sports & Outdoors | $991.55 | 279 | ★ 4.3 | 128 | SKU-001430 |
| 1432 | Deluxe Electronics Product Lite | Electronics | $118.74 | 455 | ★ 2.7 | 321 | SKU-001432 |
| 1433 | Economy Food & Grocery Product Lite | Food & Grocery | $915.59 | 389 | ★ 2.7 | 35 | SKU-001433 |
| 1434 | Standard Automotive Product Advanced | Automotive | $117.47 | 307 | ★ 1.6 | 224 | SKU-001434 |
| 1435 | Premium Sports & Outdoors Product Advanced | Sports & Outdoors | $640.58 | 388 | ★ 3.1 | 413 | SKU-001435 |
| 1436 | Premium Clothing Product 2024 | Clothing | $823.31 | 363 | ★ 1.1 | 145 | SKU-001436 |
| 1437 | Standard Toys & Games Product Lite | Toys & Games | $538.81 | 183 | ★ 2.8 | 433 | SKU-001437 |
| 1438 | Ultra Health & Beauty Product Special Edition | Health & Beauty | $978.56 | 6 | ★ 2.8 | 637 | SKU-001438 |
| 1439 | Mega Home & Garden Product Pro | Home & Garden | $397.16 | 153 | ★ 1.5 | 580 | SKU-001439 |
| 1440 | Elite Office Supplies Product Max | Office Supplies | $25.97 | 17 | ★ 4.8 | 705 | SKU-001440 |
| 1441 | Professional Automotive Product Advanced | Automotive | $932.41 | 245 | ★ 4.3 | 755 | SKU-001441 |
| 1443 | Economy Books Product Classic | Books | $411.02 | 402 | ★ 1.2 | 614 | SKU-001443 |
| 1444 | Elite Office Supplies Product Pro | Office Supplies | $129.28 | 286 | ★ 3.4 | 352 | SKU-001444 |
| 1446 | Professional Clothing Product Max | Clothing | $803.27 | 34 | ★ 1.8 | 565 | SKU-001446 |
| 1447 | Economy Food & Grocery Product XL | Food & Grocery | $874.71 | 174 | ★ 2.5 | 482 | SKU-001447 |
// 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
};
}