Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 15185 | Bulk Product ed97ad07 | Home & Garden | $806.64 | 286 | ★ 4.4 | 83 | BULK-d143ec69 |
| 15186 | Bulk Product 13b4a7d7 | Electronics | $386.46 | 124 | ★ 1.1 | 2 | BULK-750adafd |
| 15187 | Bulk Product 863bf04c | Books | $463.26 | 498 | ★ 3.5 | 86 | BULK-51d37477 |
| 15188 | Bulk Product d9eb0054 | Home & Garden | $574.77 | 16 | ★ 0.3 | 71 | BULK-d70aa196 |
| 15189 | Bulk Product 9045cd10 | Clothing | $693.74 | 291 | ★ 4.3 | 91 | BULK-7118fac5 |
| 15190 | Bulk Product 13dd6ee8 | Toys & Games | $213.45 | 21 | ★ 1.0 | 29 | BULK-44ac589f |
| 15191 | Bulk Product d02e3310 | Clothing | $541.70 | 179 | ★ 4.7 | 14 | BULK-0cd6f996 |
| 15192 | Bulk Product ef11f1b7 | Clothing | $254.41 | 153 | ★ 4.4 | 99 | BULK-f4151ca8 |
| 15193 | Bulk Product 210e8b3a | Sports & Outdoors | $140.80 | 486 | ★ 0.3 | 49 | BULK-aa67bf98 |
| 15194 | Bulk Product b332c9eb | Toys & Games | $750.84 | 215 | ★ 0.9 | 88 | BULK-fd374d82 |
| 15195 | Bulk Product 293ed38c | Sports & Outdoors | $617.58 | 488 | ★ 4.5 | 42 | BULK-7af6557c |
| 15196 | Bulk Product 7bc5745b | Toys & Games | $594.51 | 486 | ★ 3.6 | 32 | BULK-8fed494d |
| 15197 | Bulk Product 471191e8 | Electronics | $941.34 | 460 | ★ 0.5 | 65 | BULK-bf7763dd |
| 15198 | Bulk Product 3b93f20e | Home & Garden | $519.33 | 438 | ★ 0.6 | 26 | BULK-47e9a0a1 |
| 15199 | Bulk Product a9377909 | Electronics | $577.24 | 490 | ★ 1.0 | 23 | BULK-0af8bb04 |
| 15200 | Bulk Product 76a79166 | Home & Garden | $70.25 | 328 | ★ 1.3 | 65 | BULK-b3597208 |
| 15201 | Bulk Product 94d8d473 | Home & Garden | $224.88 | 33 | ★ 2.0 | 28 | BULK-be4cd495 |
| 15202 | Bulk Product 9cb78823 | Electronics | $288.30 | 403 | ★ 0.2 | 30 | BULK-dfc7cf23 |
| 15203 | Bulk Product d86e5aac | Sports & Outdoors | $962.27 | 318 | ★ 1.1 | 85 | BULK-463ef150 |
| 15204 | Bulk Product a62d5793 | Toys & Games | $578.24 | 187 | ★ 0.1 | 3 | BULK-1a922c0c |
| 15205 | Bulk Product fcec15ef | Toys & Games | $443.06 | 329 | ★ 3.3 | 54 | BULK-e26c0280 |
| 15206 | Bulk Product f10f79f7 | Toys & Games | $414.39 | 164 | ★ 4.2 | 80 | BULK-77551a95 |
| 15207 | Bulk Product 3eb69c11 | Clothing | $226.48 | 462 | ★ 0.6 | 98 | BULK-6ac924ae |
| 15208 | Bulk Product 5818ca4d | Clothing | $396.01 | 296 | ★ 3.4 | 96 | BULK-412c4663 |
| 15209 | Bulk Product a75ffe73 | Books | $725.15 | 302 | ★ 1.7 | 12 | BULK-d20eb7cd |
// 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
};
}