Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 13185 | Bulk Product 540b18fb | Home & Garden | $675.82 | 211 | ★ 3.4 | 26 | BULK-82aff00d |
| 13186 | Bulk Product e977b35c | Clothing | $251.34 | 332 | ★ 4.4 | 62 | BULK-f0b52923 |
| 13187 | Bulk Product 51ad301f | Electronics | $509.85 | 344 | ★ 1.4 | 16 | BULK-0f888a66 |
| 13188 | Bulk Product cf58038f | Sports & Outdoors | $286.85 | 436 | ★ 3.8 | 61 | BULK-2f3f6a90 |
| 13189 | Bulk Product 1ca64b12 | Home & Garden | $563.02 | 231 | ★ 3.0 | 78 | BULK-f0c0a59c |
| 13190 | Bulk Product 8d3a60be | Clothing | $155.50 | 418 | ★ 4.9 | 92 | BULK-684e97c1 |
| 13191 | Bulk Product b9333d38 | Home & Garden | $1,007.34 | 246 | ★ 1.4 | 82 | BULK-63ebb6ca |
| 13192 | Bulk Product 1eee15cf | Clothing | $581.32 | 224 | ★ 2.0 | 38 | BULK-39b780fe |
| 13193 | Bulk Product 086a517c | Clothing | $44.82 | 271 | ★ 4.5 | 9 | BULK-8eee2036 |
| 13194 | Bulk Product 51242bdb | Clothing | $855.22 | 377 | ★ 1.5 | 33 | BULK-c7338239 |
| 13195 | Bulk Product 7cd85ed0 | Home & Garden | $362.61 | 353 | ★ 2.2 | 3 | BULK-1b481ba0 |
| 13196 | Bulk Product 85f740fb | Toys & Games | $78.42 | 337 | ★ 0.8 | 92 | BULK-e701c0ec |
| 13197 | Bulk Product a187584e | Electronics | $527.29 | 273 | ★ 1.3 | 82 | BULK-9f3b5aac |
| 13198 | Bulk Product 8223413a | Home & Garden | $598.15 | 280 | ★ 4.2 | 81 | BULK-14fbbd98 |
| 13199 | Bulk Product acfe9820 | Electronics | $943.60 | 8 | ★ 3.3 | 95 | BULK-4f3ad121 |
| 13200 | Bulk Product aec761a3 | Sports & Outdoors | $582.70 | 450 | ★ 1.9 | 37 | BULK-a6aa0730 |
| 13201 | Bulk Product 64feb5f2 | Clothing | $101.83 | 351 | ★ 0.9 | 36 | BULK-e8f9ee27 |
| 13202 | Bulk Product 12c301c7 | Electronics | $714.15 | 72 | ★ 2.6 | 96 | BULK-8577d4da |
| 13203 | Bulk Product 32d97bd1 | Electronics | $966.44 | 469 | ★ 4.0 | 12 | BULK-1dda8f3d |
| 13204 | Bulk Product 23c2c6d7 | Electronics | $673.07 | 486 | ★ 0.1 | 41 | BULK-555ed7c8 |
| 13205 | Bulk Product 30e70063 | Electronics | $338.96 | 402 | ★ 3.8 | 88 | BULK-292be19f |
| 13206 | Bulk Product 0f9cd3a2 | Electronics | $974.67 | 499 | ★ 4.0 | 55 | BULK-30b56346 |
| 13207 | Bulk Product de4f0d7f | Books | $874.42 | 52 | ★ 4.5 | 50 | BULK-10ee8a02 |
| 13208 | Bulk Product ea63ec44 | Electronics | $342.80 | 225 | ★ 2.2 | 6 | BULK-b5e4e808 |
| 13209 | Bulk Product f65acffd | Home & Garden | $838.53 | 129 | ★ 3.1 | 60 | BULK-35f7d207 |
// 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
};
}