Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8385 | Bulk Product 0f279f4b | Electronics | $802.86 | 179 | ★ 2.3 | 27 | BULK-62f41891 |
| 8386 | Bulk Product cb892a58 | Toys & Games | $825.15 | 281 | ★ 2.4 | 3 | BULK-dcdde7a1 |
| 8387 | Bulk Product 6942de5d | Clothing | $119.20 | 466 | ★ 2.6 | 3 | BULK-026fd178 |
| 8388 | Bulk Product 7f106bfc | Toys & Games | $37.98 | 377 | ★ 0.9 | 89 | BULK-22edd2af |
| 8389 | Bulk Product 6d9422ff | Electronics | $975.57 | 288 | ★ 2.5 | 78 | BULK-23bb2dc5 |
| 8390 | Bulk Product 3dd9b65f | Home & Garden | $536.75 | 368 | ★ 2.1 | 2 | BULK-9546da34 |
| 8391 | Bulk Product fc277f9a | Toys & Games | $314.34 | 469 | ★ 0.1 | 42 | BULK-ea692a21 |
| 8392 | Bulk Product 8b5950a5 | Home & Garden | $532.14 | 65 | ★ 0.4 | 72 | BULK-104b6e13 |
| 8393 | Bulk Product c2159b87 | Toys & Games | $712.05 | 494 | ★ 2.8 | 94 | BULK-26555b9f |
| 8394 | Bulk Product 6cb426cb | Home & Garden | $516.06 | 76 | ★ 3.9 | 1 | BULK-21daf3e0 |
| 8395 | Bulk Product 3a89e87f | Books | $718.92 | 368 | ★ 1.5 | 47 | BULK-095ecb28 |
| 8396 | Bulk Product f06b351a | Home & Garden | $378.76 | 345 | ★ 4.1 | 1 | BULK-72378485 |
| 8397 | Bulk Product 74cc4496 | Home & Garden | $379.05 | 275 | ★ 1.3 | 98 | BULK-3b9a30e7 |
| 8398 | Bulk Product ecbbf1f3 | Sports & Outdoors | $898.58 | 172 | ★ 0.1 | 13 | BULK-f9ea908e |
| 8399 | Bulk Product 45a8f926 | Clothing | $969.50 | 324 | ★ 3.6 | 89 | BULK-bbfecf1e |
| 8400 | Bulk Product dba93e91 | Home & Garden | $885.28 | 324 | ★ 4.6 | 80 | BULK-34a2f68a |
| 8401 | Bulk Product 2887e433 | Toys & Games | $57.80 | 476 | ★ 2.1 | 66 | BULK-2c70e040 |
| 8402 | Bulk Product d02ddb58 | Electronics | $453.44 | 283 | ★ 3.5 | 78 | BULK-89f27a04 |
| 8403 | Bulk Product d7a9601f | Electronics | $378.15 | 95 | ★ 2.0 | 92 | BULK-efa33a8f |
| 8404 | Bulk Product 803d24ba | Electronics | $368.59 | 107 | ★ 0.9 | 65 | BULK-45031b24 |
| 8405 | Bulk Product 4bb8f224 | Sports & Outdoors | $418.84 | 451 | ★ 4.3 | 27 | BULK-2f9be982 |
| 8406 | Bulk Product ab883624 | Sports & Outdoors | $956.44 | 90 | ★ 4.0 | 96 | BULK-91e3151f |
| 8407 | Bulk Product eab428a5 | Clothing | $233.26 | 152 | ★ 4.7 | 25 | BULK-df9f7057 |
| 8408 | Bulk Product a08928d3 | Toys & Games | $609.35 | 164 | ★ 3.8 | 22 | BULK-fbf34ee0 |
| 8409 | Bulk Product 951a4f20 | Electronics | $894.52 | 470 | ★ 0.6 | 70 | BULK-9652057b |
// 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
};
}