Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 2145 | Mega Food & Grocery Product Lite | Food & Grocery | $290.96 | 118 | ★ 2.0 | 856 | SKU-002145 |
| 2146 | Premium Clothing Product Lite | Clothing | $745.68 | 305 | ★ 3.3 | 112 | SKU-002146 |
| 2147 | Super Toys & Games Product Advanced | Toys & Games | $67.58 | 359 | ★ 2.5 | 416 | SKU-002147 |
| 2148 | Pro Food & Grocery Product Plus | Food & Grocery | $49.51 | 315 | ★ 3.0 | 792 | SKU-002148 |
| 2149 | Super Automotive Product XL | Automotive | $972.53 | 499 | ★ 1.1 | 126 | SKU-002149 |
| 2150 | Ultra Toys & Games Product Max | Toys & Games | $131.76 | 478 | ★ 4.4 | 245 | SKU-002150 |
| 2151 | Elite Books Product 2024 | Books | $44.71 | 172 | ★ 3.8 | 833 | SKU-002151 |
| 2152 | Mega Office Supplies Product Special Edition | Office Supplies | $222.12 | 315 | ★ 3.5 | 121 | SKU-002152 |
| 2153 | Standard Automotive Product Plus | Automotive | $840.69 | 434 | ★ 3.2 | 567 | SKU-002153 |
| 2154 | Elite Electronics Product XL | Electronics | $403.74 | 310 | ★ 3.3 | 586 | SKU-002154 |
| 2155 | Standard Books Product 2024 | Books | $384.27 | 126 | ★ 4.0 | 482 | SKU-002155 |
| 2156 | Super Home & Garden Product Pro | Home & Garden | $122.45 | 336 | ★ 1.6 | 411 | SKU-002156 |
| 2157 | Standard Books Product Max | Books | $799.61 | 380 | ★ 4.9 | 71 | SKU-002157 |
| 2158 | Mega Health & Beauty Product Max | Health & Beauty | $569.41 | 79 | ★ 4.3 | 971 | SKU-002158 |
| 2160 | Ultra Office Supplies Product Advanced | Office Supplies | $269.35 | 443 | ★ 4.4 | 923 | SKU-002160 |
| 2161 | Super Electronics Product Pro | Electronics | $872.21 | 439 | ★ 3.3 | 809 | SKU-002161 |
| 2162 | Mega Food & Grocery Product Pro | Food & Grocery | $248.23 | 430 | ★ 4.5 | 666 | SKU-002162 |
| 2163 | Pro Sports & Outdoors Product Mini | Sports & Outdoors | $388.46 | 95 | ★ 1.4 | 99 | SKU-002163 |
| 2164 | Elite Electronics Product Advanced | Electronics | $313.04 | 268 | ★ 3.1 | 789 | SKU-002164 |
| 2165 | Economy Food & Grocery Product Mini | Food & Grocery | $616.86 | 29 | ★ 4.6 | 387 | SKU-002165 |
| 2166 | Standard Books Product Classic | Books | $575.06 | 384 | ★ 4.2 | 759 | SKU-002166 |
| 2167 | Mega Automotive Product Plus | Automotive | $611.81 | 376 | ★ 3.3 | 493 | SKU-002167 |
| 2168 | Pro Office Supplies Product Max | Office Supplies | $591.76 | 193 | ★ 4.2 | 439 | SKU-002168 |
| 2169 | Premium Office Supplies Product Pro | Office Supplies | $993.58 | 438 | ★ 2.8 | 438 | SKU-002169 |
| 2170 | Standard Home & Garden Product Special Edition | Home & Garden | $793.18 | 118 | ★ 3.9 | 742 | SKU-002170 |
// 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
};
}