Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 15410 | Bulk Product 6f370438 | Clothing | $272.61 | 101 | ★ 3.1 | 72 | BULK-af01042e |
| 15411 | Bulk Product 51cecde9 | Electronics | $406.37 | 260 | ★ 0.3 | 88 | BULK-37bd5c2b |
| 15412 | Bulk Product f450fd76 | Home & Garden | $217.93 | 341 | ★ 2.1 | 62 | BULK-19c0f1ca |
| 15413 | Bulk Product fdc1471a | Sports & Outdoors | $768.42 | 345 | ★ 4.1 | 17 | BULK-d22a54e3 |
| 15414 | Bulk Product df142dec | Home & Garden | $663.35 | 298 | ★ 1.8 | 8 | BULK-23e921be |
| 15415 | Bulk Product 2e49bb77 | Books | $397.99 | 289 | ★ 0.3 | 27 | BULK-66647cbf |
| 15416 | Bulk Product 7e8e0571 | Electronics | $338.49 | 370 | ★ 3.3 | 61 | BULK-e91b42f7 |
| 15417 | Bulk Product 66e2c219 | Home & Garden | $54.80 | 6 | ★ 0.4 | 27 | BULK-c7d45d24 |
| 15418 | Bulk Product f2495cdd | Clothing | $794.02 | 110 | ★ 3.8 | 70 | BULK-10ce0dc1 |
| 15419 | Bulk Product dea20240 | Electronics | $149.45 | 453 | ★ 0.9 | 4 | BULK-72d364a2 |
| 15420 | Bulk Product 59302905 | Electronics | $514.75 | 374 | ★ 3.1 | 57 | BULK-918fe897 |
| 15421 | Bulk Product d5be4ac5 | Toys & Games | $438.87 | 314 | ★ 0.6 | 89 | BULK-defb860f |
| 15422 | Bulk Product f3949478 | Clothing | $196.32 | 107 | ★ 0.0 | 52 | BULK-2dea7fd3 |
| 15423 | Bulk Product 7ab8a28b | Clothing | $218.16 | 228 | ★ 2.8 | 98 | BULK-8bc89157 |
| 15424 | Bulk Product 721ad48a | Toys & Games | $495.55 | 426 | ★ 2.3 | 44 | BULK-eb6376fe |
| 15425 | Bulk Product 74727fe0 | Electronics | $181.56 | 263 | ★ 4.5 | 99 | BULK-318cdf9f |
| 15426 | Bulk Product 9a67e761 | Electronics | $924.17 | 429 | ★ 1.6 | 62 | BULK-862a2138 |
| 15427 | Bulk Product 7f77cb0d | Electronics | $323.92 | 25 | ★ 4.9 | 12 | BULK-d143c8fc |
| 15428 | Bulk Product 0b5083cb | Home & Garden | $276.40 | 392 | ★ 0.8 | 99 | BULK-27f56552 |
| 15429 | Bulk Product 2756f343 | Toys & Games | $842.94 | 108 | ★ 0.3 | 33 | BULK-205a83cb |
| 15430 | Bulk Product a48a00b7 | Clothing | $422.52 | 200 | ★ 2.2 | 66 | BULK-db872011 |
| 15431 | Bulk Product a236ee50 | Books | $792.17 | 268 | ★ 4.9 | 19 | BULK-23fc0078 |
| 15432 | Bulk Product 94c9669e | Toys & Games | $86.93 | 489 | ★ 4.6 | 93 | BULK-81d56047 |
| 15433 | Bulk Product f2fe5d5a | Electronics | $825.39 | 152 | ★ 0.2 | 56 | BULK-4cffbd6c |
| 15434 | Bulk Product 3e4d1977 | Sports & Outdoors | $659.22 | 327 | ★ 2.7 | 82 | BULK-e5c3d7db |
// 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
};
}