Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17660 | Bulk Product ed5a4842 | Books | $190.76 | 141 | ★ 2.4 | 32 | BULK-d87bcefe |
| 17661 | Bulk Product 783f2e2a | Home & Garden | $998.88 | 7 | ★ 0.3 | 82 | BULK-1e7c3f9a |
| 17662 | Bulk Product 45db0e96 | Electronics | $161.38 | 365 | ★ 3.2 | 16 | BULK-feaab0c0 |
| 17663 | Bulk Product 592e42bb | Clothing | $979.00 | 158 | ★ 1.8 | 85 | BULK-6e84146d |
| 17664 | Bulk Product f40066e1 | Sports & Outdoors | $40.90 | 405 | ★ 2.5 | 56 | BULK-81e160f2 |
| 17665 | Bulk Product 6b82e0a8 | Toys & Games | $795.14 | 82 | ★ 0.0 | 75 | BULK-8eca28f7 |
| 17666 | Bulk Product f25811ed | Sports & Outdoors | $112.73 | 120 | ★ 1.0 | 57 | BULK-cf41a7d4 |
| 17667 | Bulk Product f0a788e5 | Home & Garden | $618.80 | 498 | ★ 3.1 | 41 | BULK-efa9543f |
| 17668 | Bulk Product c498a28f | Electronics | $930.86 | 165 | ★ 0.8 | 19 | BULK-8dd67e78 |
| 17669 | Bulk Product 9e9941a3 | Clothing | $768.44 | 371 | ★ 1.6 | 52 | BULK-65e695c8 |
| 17670 | Bulk Product f4f68516 | Toys & Games | $174.77 | 127 | ★ 4.4 | 57 | BULK-80516f62 |
| 17671 | Bulk Product 143c64d5 | Toys & Games | $537.90 | 276 | ★ 3.1 | 68 | BULK-5f34990b |
| 17672 | Bulk Product 7d370719 | Books | $342.00 | 461 | ★ 1.4 | 53 | BULK-11003a0d |
| 17673 | Bulk Product f9fd689b | Sports & Outdoors | $833.61 | 117 | ★ 0.4 | 98 | BULK-aae96f4f |
| 17674 | Bulk Product 4102118c | Clothing | $55.72 | 269 | ★ 1.9 | 73 | BULK-c6e1dae9 |
| 17675 | Bulk Product d0a56e40 | Books | $202.66 | 105 | ★ 4.2 | 11 | BULK-47d8f99e |
| 17676 | Bulk Product a38c7a18 | Toys & Games | $699.95 | 277 | ★ 2.1 | 27 | BULK-6ca93f86 |
| 17677 | Bulk Product 6a3d4545 | Sports & Outdoors | $614.88 | 37 | ★ 0.4 | 41 | BULK-1c69e554 |
| 17678 | Bulk Product 090c05f5 | Clothing | $971.84 | 235 | ★ 2.3 | 68 | BULK-55dc26de |
| 17679 | Bulk Product 3f79edd6 | Electronics | $569.73 | 45 | ★ 3.5 | 79 | BULK-5e335bcf |
| 17680 | Bulk Product 5eac6551 | Sports & Outdoors | $564.58 | 215 | ★ 3.4 | 79 | BULK-5ab91882 |
| 17681 | Bulk Product a80a1c7b | Electronics | $773.74 | 460 | ★ 1.8 | 54 | BULK-839b5cd6 |
| 17682 | Bulk Product 567e57be | Sports & Outdoors | $1,007.56 | 114 | ★ 0.3 | 64 | BULK-f8cc5569 |
| 17683 | Bulk Product 2f8e5f5f | Clothing | $721.85 | 296 | ★ 3.7 | 7 | BULK-c324ff99 |
| 17684 | Bulk Product ce4b86ce | Home & Garden | $248.56 | 29 | ★ 3.7 | 64 | BULK-c46b0e73 |
// 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
};
}