Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 57 | Premium Office Supplies Product Classic | Office Supplies | $657.88 | 268 | ★ 4.3 | 521 | SKU-000057 |
| 58 | Pro Toys & Games Product Max | Toys & Games | $182.95 | 238 | ★ 2.6 | 552 | SKU-000058 |
| 59 | Elite Home & Garden Product 2024 | Home & Garden | $777.88 | 400 | ★ 3.6 | 813 | SKU-000059 |
| 60 | Standard Automotive Product Classic | Automotive | $161.46 | 112 | ★ 3.3 | 374 | SKU-000060 |
| 61 | Economy Automotive Product Pro | Automotive | $307.55 | 356 | ★ 4.3 | 19 | SKU-000061 |
| 62 | Ultra Clothing Product XL | Clothing | $811.94 | 15 | ★ 2.4 | 350 | SKU-000062 |
| 63 | Pro Health & Beauty Product Classic | Health & Beauty | $384.62 | 90 | ★ 4.8 | 880 | SKU-000063 |
| 64 | Super Food & Grocery Product Plus | Food & Grocery | $711.82 | 104 | ★ 2.8 | 948 | SKU-000064 |
| 66 | Mega Toys & Games Product XL | Toys & Games | $715.54 | 94 | ★ 4.1 | 60 | SKU-000066 |
| 67 | Professional Clothing Product Pro | Clothing | $241.55 | 50 | ★ 4.2 | 628 | SKU-000067 |
| 68 | Elite Sports & Outdoors Product 2024 | Sports & Outdoors | $270.51 | 300 | ★ 2.9 | 614 | SKU-000068 |
| 69 | Elite Automotive Product Advanced | Automotive | $373.70 | 246 | ★ 3.1 | 427 | SKU-000069 |
| 70 | Super Office Supplies Product Plus | Office Supplies | $616.89 | 80 | ★ 4.1 | 990 | SKU-000070 |
| 71 | Mega Books Product Plus | Books | $818.77 | 6 | ★ 3.8 | 712 | SKU-000071 |
| 72 | Pro Food & Grocery Product Mini | Food & Grocery | $763.67 | 406 | ★ 4.4 | 974 | SKU-000072 |
| 73 | Standard Automotive Product Lite | Automotive | $490.99 | 324 | ★ 2.8 | 672 | SKU-000073 |
| 74 | Mega Toys & Games Product Mini | Toys & Games | $893.26 | 335 | ★ 1.7 | 773 | SKU-000074 |
| 75 | Economy Automotive Product Max | Automotive | $827.71 | 432 | ★ 4.9 | 681 | SKU-000075 |
| 77 | Economy Toys & Games Product Special Edition | Toys & Games | $600.74 | 193 | ★ 4.9 | 315 | SKU-000077 |
| 78 | Deluxe Office Supplies Product XL | Office Supplies | $953.02 | 248 | ★ 3.6 | 299 | SKU-000078 |
| 79 | Deluxe Books Product Mini | Books | $864.07 | 332 | ★ 2.9 | 763 | SKU-000079 |
| 81 | Ultra Food & Grocery Product Max | Food & Grocery | $961.23 | 67 | ★ 3.3 | 743 | SKU-000081 |
| 82 | Super Food & Grocery Product XL | Food & Grocery | $825.65 | 349 | ★ 4.2 | 639 | SKU-000082 |
| 83 | Professional Books Product Special Edition | Books | $205.90 | 194 | ★ 4.5 | 209 | SKU-000083 |
| 84 | Ultra Office Supplies Product 2024 | Office Supplies | $889.42 | 498 | ★ 3.4 | 100 | SKU-000084 |
// 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
};
}