Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 22660 | Bulk Product 3456b475 | Clothing | $782.68 | 468 | ★ 1.7 | 70 | BULK-63c9991d |
| 22661 | Bulk Product 75ce57e1 | Sports & Outdoors | $938.91 | 348 | ★ 1.4 | 5 | BULK-b482475d |
| 22662 | Bulk Product d2e4945c | Clothing | $574.09 | 489 | ★ 2.4 | 15 | BULK-9f10fa69 |
| 22663 | Bulk Product 44749aa6 | Toys & Games | $268.03 | 135 | ★ 0.0 | 21 | BULK-16e585aa |
| 22664 | Bulk Product f4388c19 | Sports & Outdoors | $944.63 | 468 | ★ 4.9 | 76 | BULK-49a9e365 |
| 22665 | Bulk Product fcbc940c | Books | $862.27 | 432 | ★ 1.9 | 16 | BULK-723f9982 |
| 22666 | Bulk Product ee6dd752 | Home & Garden | $519.98 | 380 | ★ 3.2 | 24 | BULK-e8a8b385 |
| 22667 | Bulk Product ead33b58 | Toys & Games | $72.49 | 483 | ★ 0.5 | 65 | BULK-e44802c1 |
| 22668 | Bulk Product dfb11c83 | Electronics | $122.43 | 203 | ★ 4.2 | 53 | BULK-9ae71355 |
| 22669 | Bulk Product 05f74982 | Toys & Games | $342.87 | 114 | ★ 0.7 | 93 | BULK-339c088b |
| 22670 | Bulk Product 17dad11b | Home & Garden | $982.49 | 203 | ★ 4.6 | 32 | BULK-8020e111 |
| 22671 | Bulk Product d955b2e5 | Sports & Outdoors | $1,002.83 | 64 | ★ 1.6 | 90 | BULK-15b40e03 |
| 22672 | Bulk Product 4f9bc504 | Sports & Outdoors | $549.76 | 327 | ★ 2.3 | 43 | BULK-354779d3 |
| 22673 | Bulk Product b19843c8 | Home & Garden | $584.62 | 495 | ★ 3.0 | 54 | BULK-944f4de4 |
| 22674 | Bulk Product 3a75d97a | Clothing | $137.38 | 145 | ★ 3.1 | 6 | BULK-2882a22d |
| 22675 | Bulk Product 3275123b | Books | $771.83 | 451 | ★ 2.5 | 51 | BULK-b9f175bb |
| 22676 | Bulk Product dc56f604 | Clothing | $118.47 | 327 | ★ 2.5 | 2 | BULK-4af12eac |
| 22677 | Bulk Product 392ad357 | Books | $163.07 | 196 | ★ 3.5 | 68 | BULK-ad86627b |
| 22678 | Bulk Product 976a8301 | Clothing | $85.99 | 276 | ★ 2.0 | 32 | BULK-edaae9c3 |
| 22679 | Bulk Product bc372a3a | Electronics | $556.84 | 272 | ★ 3.1 | 31 | BULK-1d900d37 |
| 22680 | Bulk Product 99535c5b | Sports & Outdoors | $218.11 | 6 | ★ 3.2 | 44 | BULK-266a7866 |
| 22681 | Bulk Product 7a37d1d9 | Toys & Games | $709.71 | 103 | ★ 0.9 | 74 | BULK-14045020 |
| 22682 | Bulk Product 76e42ed1 | Toys & Games | $524.31 | 380 | ★ 1.2 | 25 | BULK-c00dd572 |
| 22683 | Bulk Product 27fc41cb | Toys & Games | $228.48 | 8 | ★ 1.5 | 65 | BULK-f9a9d658 |
| 22684 | Bulk Product 8cf462ae | Sports & Outdoors | $333.86 | 279 | ★ 4.0 | 7 | BULK-79400eae |
// 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
};
}