Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 18235 | Bulk Product d7e43b07 | Electronics | $300.32 | 377 | ★ 2.1 | 50 | BULK-4383167e |
| 18236 | Bulk Product 79fbe385 | Clothing | $29.25 | 194 | ★ 2.2 | 61 | BULK-f57bb937 |
| 18237 | Bulk Product 7ff11fc2 | Electronics | $735.05 | 149 | ★ 4.2 | 31 | BULK-a80ae9fe |
| 18238 | Bulk Product a12cb7fe | Home & Garden | $495.17 | 40 | ★ 4.4 | 94 | BULK-0f358910 |
| 18239 | Bulk Product f92473f9 | Books | $348.10 | 98 | ★ 3.1 | 46 | BULK-c75ac04c |
| 18240 | Bulk Product f75e6eee | Clothing | $185.67 | 0 | ★ 0.9 | 98 | BULK-41e99de1 |
| 18241 | Bulk Product 11df5dae | Toys & Games | $777.13 | 121 | ★ 2.6 | 1 | BULK-e82904a0 |
| 18242 | Bulk Product d7742d2e | Electronics | $441.85 | 464 | ★ 0.8 | 69 | BULK-7af28e0d |
| 18243 | Bulk Product 66a9b5db | Home & Garden | $530.10 | 187 | ★ 0.3 | 81 | BULK-a76c0939 |
| 18244 | Bulk Product 09fc2cee | Toys & Games | $727.64 | 494 | ★ 3.0 | 71 | BULK-6de926b4 |
| 18245 | Bulk Product d51f5338 | Sports & Outdoors | $503.68 | 468 | ★ 2.2 | 43 | BULK-deebc626 |
| 18246 | Bulk Product 76605b7c | Clothing | $356.54 | 378 | ★ 2.8 | 60 | BULK-41222359 |
| 18247 | Bulk Product 49825187 | Books | $901.35 | 22 | ★ 3.7 | 83 | BULK-72e124f5 |
| 18248 | Bulk Product 6e238eb1 | Sports & Outdoors | $950.36 | 228 | ★ 1.6 | 98 | BULK-a8ea32e5 |
| 18249 | Bulk Product b910ab6a | Home & Garden | $209.11 | 280 | ★ 4.3 | 56 | BULK-b30cb2b6 |
| 18250 | Bulk Product 9264ab12 | Home & Garden | $973.01 | 302 | ★ 0.0 | 98 | BULK-78ee904d |
| 18251 | Bulk Product fea98cfd | Sports & Outdoors | $965.66 | 8 | ★ 1.2 | 14 | BULK-9a18ce2e |
| 18252 | Bulk Product cc2e290c | Home & Garden | $618.68 | 494 | ★ 2.9 | 6 | BULK-4fce42b7 |
| 18253 | Bulk Product b6be60d9 | Books | $593.05 | 192 | ★ 1.1 | 89 | BULK-1fe10002 |
| 18254 | Bulk Product 0fe69fe4 | Home & Garden | $481.17 | 299 | ★ 4.5 | 84 | BULK-95272888 |
| 18255 | Bulk Product 4cb49586 | Clothing | $119.66 | 5 | ★ 3.0 | 27 | BULK-7576c6cd |
| 18256 | Bulk Product 78d3665c | Electronics | $608.48 | 474 | ★ 0.6 | 1 | BULK-6632b33c |
| 18257 | Bulk Product 6505d62c | Toys & Games | $503.59 | 245 | ★ 4.1 | 92 | BULK-541d087e |
| 18258 | Bulk Product 8598cdc0 | Sports & Outdoors | $235.15 | 103 | ★ 3.8 | 26 | BULK-d31769bc |
| 18259 | Bulk Product 6062621e | Books | $334.87 | 185 | ★ 3.3 | 11 | BULK-6bab9dbc |
// 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
};
}