Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1330 | Standard Health & Beauty Product Max | Health & Beauty | $481.45 | 438 | ★ 4.7 | 199 | SKU-001330 |
| 1332 | Deluxe Sports & Outdoors Product Advanced | Sports & Outdoors | $698.91 | 3 | ★ 2.6 | 692 | SKU-001332 |
| 1333 | Economy Food & Grocery Product Advanced | Food & Grocery | $341.32 | 204 | ★ 3.7 | 639 | SKU-001333 |
| 1334 | Super Clothing Product Special Edition | Clothing | $217.64 | 49 | ★ 4.4 | 392 | SKU-001334 |
| 1335 | Ultra Sports & Outdoors Product Mini | Sports & Outdoors | $642.01 | 298 | ★ 1.1 | 807 | SKU-001335 |
| 1336 | Elite Clothing Product Max | Clothing | $815.53 | 191 | ★ 2.9 | 73 | SKU-001336 |
| 1337 | Professional Books Product Pro | Books | $530.74 | 263 | ★ 1.6 | 983 | SKU-001337 |
| 1338 | Mega Home & Garden Product Special Edition | Home & Garden | $718.30 | 163 | ★ 2.5 | 368 | SKU-001338 |
| 1339 | Pro Office Supplies Product Pro | Office Supplies | $363.35 | 341 | ★ 2.6 | 505 | SKU-001339 |
| 1341 | Standard Books Product Lite | Books | $192.45 | 240 | ★ 3.5 | 478 | SKU-001341 |
| 1342 | Economy Automotive Product Special Edition | Automotive | $624.59 | 171 | ★ 1.8 | 219 | SKU-001342 |
| 1343 | Ultra Toys & Games Product XL | Toys & Games | $704.58 | 479 | ★ 2.0 | 574 | SKU-001343 |
| 1344 | Pro Home & Garden Product XL | Home & Garden | $865.44 | 169 | ★ 5.0 | 634 | SKU-001344 |
| 1345 | Standard Clothing Product Pro | Clothing | $172.63 | 68 | ★ 3.6 | 843 | SKU-001345 |
| 1346 | Ultra Food & Grocery Product Classic | Food & Grocery | $356.07 | 191 | ★ 2.4 | 87 | SKU-001346 |
| 1347 | Ultra Toys & Games Product Advanced | Toys & Games | $333.29 | 255 | ★ 4.8 | 311 | SKU-001347 |
| 1348 | Mega Health & Beauty Product Mini | Health & Beauty | $722.72 | 85 | ★ 1.8 | 13 | SKU-001348 |
| 1350 | Professional Office Supplies Product Mini | Office Supplies | $188.27 | 44 | ★ 3.2 | 16 | SKU-001350 |
| 1352 | Super Sports & Outdoors Product Classic | Sports & Outdoors | $201.95 | 259 | ★ 1.1 | 316 | SKU-001352 |
| 1353 | Professional Toys & Games Product Plus | Toys & Games | $764.40 | 111 | ★ 3.8 | 546 | SKU-001353 |
| 1354 | Standard Food & Grocery Product Lite | Food & Grocery | $704.98 | 84 | ★ 3.6 | 394 | SKU-001354 |
| 1355 | Super Sports & Outdoors Product Special Edition | Sports & Outdoors | $468.33 | 139 | ★ 1.4 | 277 | SKU-001355 |
| 1356 | Professional Food & Grocery Product Advanced | Food & Grocery | $464.59 | 416 | ★ 3.0 | 401 | SKU-001356 |
| 1357 | Super Electronics Product Advanced | Electronics | $788.28 | 124 | ★ 3.8 | 644 | SKU-001357 |
| 1358 | Standard Clothing Product 2024 | Clothing | $198.25 | 343 | ★ 4.2 | 756 | SKU-001358 |
// 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
};
}