Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 21535 | Bulk Product 7e3040b2 | Toys & Games | $628.68 | 93 | ★ 2.0 | 52 | BULK-8697795e |
| 21536 | Bulk Product 9eb21074 | Books | $977.16 | 164 | ★ 3.0 | 52 | BULK-57df274a |
| 21537 | Bulk Product fdff2268 | Home & Garden | $198.50 | 90 | ★ 1.9 | 70 | BULK-81e70ffb |
| 21538 | Bulk Product f62db69a | Home & Garden | $414.95 | 393 | ★ 2.5 | 24 | BULK-0055a82d |
| 21539 | Bulk Product 4be5f5f6 | Clothing | $574.97 | 3 | ★ 1.9 | 41 | BULK-5c93dc97 |
| 21540 | Bulk Product e867ffa6 | Clothing | $92.38 | 355 | ★ 2.9 | 85 | BULK-66eba215 |
| 21541 | Bulk Product 699dc47b | Books | $736.12 | 299 | ★ 4.1 | 84 | BULK-50cd22f3 |
| 21542 | Bulk Product 8619dba9 | Sports & Outdoors | $293.88 | 23 | ★ 0.4 | 63 | BULK-d0e8dc29 |
| 21543 | Bulk Product 35857f44 | Books | $756.07 | 431 | ★ 2.4 | 19 | BULK-44df593c |
| 21544 | Bulk Product 73c2276c | Books | $762.07 | 265 | ★ 4.1 | 21 | BULK-cf731247 |
| 21545 | Bulk Product 004f9578 | Toys & Games | $29.00 | 148 | ★ 2.8 | 8 | BULK-d9482ad1 |
| 21546 | Bulk Product d7421e1e | Home & Garden | $228.42 | 321 | ★ 2.7 | 66 | BULK-317cb7f0 |
| 21547 | Bulk Product ef9b50f6 | Clothing | $577.70 | 371 | ★ 3.3 | 88 | BULK-935860ce |
| 21548 | Bulk Product 207e811b | Books | $332.72 | 178 | ★ 2.2 | 88 | BULK-9c0bf517 |
| 21549 | Bulk Product 0ff64d98 | Electronics | $338.82 | 240 | ★ 2.9 | 93 | BULK-4451d025 |
| 21550 | Bulk Product 187a7bc9 | Toys & Games | $599.39 | 340 | ★ 3.2 | 41 | BULK-cf0ce3a8 |
| 21551 | Bulk Product 7982c05c | Sports & Outdoors | $82.37 | 294 | ★ 0.1 | 60 | BULK-99380819 |
| 21552 | Bulk Product 9a5394ec | Clothing | $284.62 | 355 | ★ 3.6 | 52 | BULK-804a7e46 |
| 21553 | Bulk Product 0578be83 | Electronics | $303.89 | 72 | ★ 1.6 | 31 | BULK-77534a13 |
| 21554 | Bulk Product 8941b129 | Toys & Games | $854.59 | 382 | ★ 0.3 | 68 | BULK-619e5961 |
| 21555 | Bulk Product 13ee27c3 | Clothing | $574.71 | 483 | ★ 3.3 | 95 | BULK-10eaf370 |
| 21556 | Bulk Product ae091436 | Sports & Outdoors | $50.19 | 490 | ★ 0.8 | 6 | BULK-3b348682 |
| 21557 | Bulk Product 1b7fed93 | Books | $170.93 | 11 | ★ 2.5 | 88 | BULK-4678e812 |
| 21558 | Bulk Product 52dc114b | Books | $878.60 | 176 | ★ 0.8 | 89 | BULK-833e01fd |
| 21559 | Bulk Product f1cbec1d | Books | $687.68 | 20 | ★ 0.2 | 38 | BULK-4e9788b6 |
// 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
};
}