Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 9360 | Bulk Product cbf6842a | Home & Garden | $124.07 | 427 | ★ 2.4 | 76 | BULK-7d37106e |
| 9361 | Bulk Product b8147028 | Toys & Games | $86.24 | 437 | ★ 4.8 | 14 | BULK-2790574e |
| 9362 | Bulk Product 5c21e382 | Electronics | $593.49 | 294 | ★ 0.7 | 25 | BULK-5d480850 |
| 9363 | Bulk Product 3b861bab | Toys & Games | $412.61 | 154 | ★ 3.1 | 24 | BULK-152c9b4c |
| 9364 | Bulk Product 3c45eaf2 | Books | $995.81 | 411 | ★ 4.4 | 33 | BULK-c710241f |
| 9365 | Bulk Product 2731fc80 | Home & Garden | $88.79 | 357 | ★ 3.5 | 72 | BULK-43458cc2 |
| 9366 | Bulk Product 94e798b0 | Books | $746.66 | 418 | ★ 2.3 | 36 | BULK-530d9279 |
| 9367 | Bulk Product 6bf8531a | Clothing | $812.59 | 157 | ★ 0.4 | 85 | BULK-22d450f3 |
| 9368 | Bulk Product 39f99ed6 | Books | $525.97 | 376 | ★ 1.2 | 80 | BULK-2ceda8ed |
| 9369 | Bulk Product c0c13c56 | Toys & Games | $231.17 | 259 | ★ 3.1 | 12 | BULK-95239a65 |
| 9370 | Bulk Product df03c724 | Books | $837.21 | 476 | ★ 4.6 | 63 | BULK-ae1d75b9 |
| 9371 | Bulk Product 99cd362e | Electronics | $582.32 | 441 | ★ 3.5 | 79 | BULK-c1b9f308 |
| 9372 | Bulk Product ab29b0ff | Home & Garden | $137.24 | 108 | ★ 0.1 | 54 | BULK-0cf49399 |
| 9373 | Bulk Product e8ddc266 | Home & Garden | $174.13 | 78 | ★ 4.2 | 24 | BULK-0bac9935 |
| 9374 | Bulk Product 7edd32e6 | Electronics | $763.69 | 101 | ★ 1.8 | 77 | BULK-0aeabe05 |
| 9375 | Bulk Product 50bc47aa | Clothing | $764.68 | 194 | ★ 1.4 | 51 | BULK-cd62dedf |
| 9376 | Bulk Product b7d960d7 | Electronics | $501.30 | 203 | ★ 3.8 | 64 | BULK-ab91d02c |
| 9377 | Bulk Product c495e79c | Sports & Outdoors | $885.38 | 184 | ★ 1.9 | 1 | BULK-eaca65a4 |
| 9378 | Bulk Product 9f2b9e05 | Sports & Outdoors | $266.11 | 494 | ★ 1.6 | 6 | BULK-f5a9e631 |
| 9379 | Bulk Product a4222913 | Home & Garden | $928.92 | 281 | ★ 3.7 | 78 | BULK-f1ef7806 |
| 9380 | Bulk Product 5e7a3ee2 | Electronics | $800.59 | 467 | ★ 1.9 | 25 | BULK-750b5178 |
| 9381 | Bulk Product a0aedb5c | Home & Garden | $262.80 | 109 | ★ 0.6 | 97 | BULK-2daf471a |
| 9382 | Bulk Product 2f61e37c | Electronics | $434.87 | 154 | ★ 1.8 | 16 | BULK-0155e69d |
| 9383 | Bulk Product f5c85899 | Electronics | $45.34 | 24 | ★ 1.4 | 34 | BULK-ac242653 |
| 9384 | Bulk Product 55a232da | Sports & Outdoors | $263.65 | 212 | ★ 2.7 | 56 | BULK-308f6ff5 |
// 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
};
}