Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1360 | Professional Office Supplies Product Pro | Office Supplies | $987.21 | 127 | ★ 1.2 | 281 | SKU-001360 |
| 1361 | Elite Books Product Advanced | Books | $160.80 | 146 | ★ 3.9 | 709 | SKU-001361 |
| 1362 | Standard Automotive Product Advanced | Automotive | $161.56 | 187 | ★ 4.9 | 642 | SKU-001362 |
| 1363 | Professional Clothing Product Pro | Clothing | $91.72 | 59 | ★ 4.0 | 114 | SKU-001363 |
| 1364 | Standard Food & Grocery Product 2024 | Food & Grocery | $290.10 | 1 | ★ 1.2 | 80 | SKU-001364 |
| 1365 | Elite Books Product Lite | Books | $666.92 | 320 | ★ 2.9 | 914 | SKU-001365 |
| 1366 | Pro Automotive Product Special Edition | Automotive | $560.34 | 386 | ★ 1.2 | 327 | SKU-001366 |
| 1367 | Deluxe Automotive Product 2024 | Automotive | $433.75 | 467 | ★ 1.9 | 668 | SKU-001367 |
| 1370 | Deluxe Food & Grocery Product Mini | Food & Grocery | $700.74 | 379 | ★ 4.2 | 55 | SKU-001370 |
| 1371 | Super Clothing Product 2024 | Clothing | $803.92 | 128 | ★ 2.5 | 499 | SKU-001371 |
| 1373 | Pro Office Supplies Product Lite | Office Supplies | $45.29 | 72 | ★ 4.4 | 672 | SKU-001373 |
| 1374 | Premium Toys & Games Product Advanced | Toys & Games | $792.31 | 371 | ★ 1.7 | 428 | SKU-001374 |
| 1375 | Economy Office Supplies Product Classic | Office Supplies | $345.14 | 360 | ★ 2.5 | 250 | SKU-001375 |
| 1377 | Super Books Product Pro | Books | $903.59 | 135 | ★ 3.4 | 687 | SKU-001377 |
| 1379 | Premium Electronics Product Max | Electronics | $680.70 | 200 | ★ 1.7 | 105 | SKU-001379 |
| 1381 | Standard Food & Grocery Product 2024 | Food & Grocery | $382.30 | 337 | ★ 4.8 | 925 | SKU-001381 |
| 1382 | Pro Clothing Product Max | Clothing | $585.01 | 200 | ★ 4.1 | 834 | SKU-001382 |
| 1384 | Elite Toys & Games Product Advanced | Toys & Games | $842.90 | 97 | ★ 3.6 | 984 | SKU-001384 |
| 1385 | Ultra Toys & Games Product Advanced | Toys & Games | $590.41 | 343 | ★ 4.5 | 633 | SKU-001385 |
| 1386 | Ultra Toys & Games Product Classic | Toys & Games | $816.66 | 439 | ★ 1.8 | 40 | SKU-001386 |
| 1388 | Professional Health & Beauty Product Mini | Health & Beauty | $519.20 | 379 | ★ 3.7 | 108 | SKU-001388 |
| 1389 | Super Office Supplies Product Max | Office Supplies | $514.47 | 159 | ★ 3.6 | 299 | SKU-001389 |
| 1390 | Mega Automotive Product Classic | Automotive | $591.45 | 256 | ★ 2.5 | 436 | SKU-001390 |
| 1391 | Pro Sports & Outdoors Product Special Edition | Sports & Outdoors | $333.07 | 382 | ★ 4.2 | 392 | SKU-001391 |
| 1392 | Elite Sports & Outdoors Product Plus | Sports & Outdoors | $755.88 | 272 | ★ 1.4 | 140 | SKU-001392 |
// 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
};
}