Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 1536 | Standard Food & Grocery Product Plus | Food & Grocery | $614.13 | 487 | ★ 2.7 | 198 | SKU-001536 |
| 1537 | Deluxe Sports & Outdoors Product 2024 | Sports & Outdoors | $886.80 | 220 | ★ 3.2 | 575 | SKU-001537 |
| 1538 | Elite Automotive Product XL | Automotive | $940.11 | 141 | ★ 1.6 | 660 | SKU-001538 |
| 1539 | Professional Toys & Games Product Special Edition | Toys & Games | $550.19 | 88 | ★ 2.6 | 722 | SKU-001539 |
| 1540 | Professional Toys & Games Product Plus | Toys & Games | $320.00 | 131 | ★ 3.0 | 976 | SKU-001540 |
| 1541 | Standard Books Product Max | Books | $272.13 | 328 | ★ 3.9 | 566 | SKU-001541 |
| 1542 | Super Food & Grocery Product 2024 | Food & Grocery | $63.13 | 122 | ★ 2.3 | 649 | SKU-001542 |
| 1543 | Premium Toys & Games Product Pro | Toys & Games | $465.17 | 76 | ★ 2.3 | 764 | SKU-001543 |
| 1544 | Standard Electronics Product Pro | Electronics | $524.83 | 467 | ★ 1.6 | 368 | SKU-001544 |
| 1545 | Professional Books Product Advanced | Books | $54.09 | 54 | ★ 2.6 | 801 | SKU-001545 |
| 1546 | Deluxe Home & Garden Product Lite | Home & Garden | $19.32 | 444 | ★ 3.8 | 8 | SKU-001546 |
| 1547 | Pro Books Product Max | Books | $359.38 | 8 | ★ 4.8 | 744 | SKU-001547 |
| 1548 | Super Food & Grocery Product Special Edition | Food & Grocery | $717.29 | 248 | ★ 3.0 | 425 | SKU-001548 |
| 1549 | Economy Automotive Product 2024 | Automotive | $97.02 | 322 | ★ 4.2 | 779 | SKU-001549 |
| 1551 | Standard Books Product 2024 | Books | $56.00 | 80 | ★ 1.8 | 636 | SKU-001551 |
| 1552 | Economy Toys & Games Product Special Edition | Toys & Games | $946.50 | 321 | ★ 1.8 | 840 | SKU-001552 |
| 1553 | Professional Food & Grocery Product Lite | Food & Grocery | $572.33 | 223 | ★ 3.8 | 15 | SKU-001553 |
| 1554 | Mega Home & Garden Product Lite | Home & Garden | $915.04 | 374 | ★ 3.7 | 607 | SKU-001554 |
| 1555 | Mega Clothing Product Plus | Clothing | $16.82 | 193 | ★ 4.8 | 956 | SKU-001555 |
| 1557 | Pro Clothing Product Advanced | Clothing | $718.96 | 492 | ★ 4.5 | 611 | SKU-001557 |
| 1558 | Super Health & Beauty Product Plus | Health & Beauty | $632.42 | 85 | ★ 2.8 | 746 | SKU-001558 |
| 1559 | Professional Electronics Product Special Edition | Electronics | $133.05 | 183 | ★ 4.0 | 590 | SKU-001559 |
| 1560 | Economy Food & Grocery Product XL | Food & Grocery | $821.53 | 144 | ★ 3.1 | 382 | SKU-001560 |
| 1561 | Ultra Clothing Product XL | Clothing | $338.11 | 158 | ★ 3.2 | 793 | SKU-001561 |
| 1562 | Economy Health & Beauty Product Max | Health & Beauty | $426.98 | 227 | ★ 3.3 | 614 | SKU-001562 |
// 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
};
}