Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8035 | Bulk Product 1d100d54 | Sports & Outdoors | $68.07 | 488 | ★ 3.7 | 31 | BULK-b69eb87f |
| 8036 | Bulk Product a92ebdd7 | Books | $108.27 | 454 | ★ 3.2 | 64 | BULK-c05e4feb |
| 8037 | Bulk Product 21b059c6 | Electronics | $34.34 | 205 | ★ 2.1 | 40 | BULK-0dadc1ad |
| 8038 | Bulk Product 0b9c4bf3 | Sports & Outdoors | $863.46 | 152 | ★ 1.8 | 74 | BULK-746a3199 |
| 8039 | Bulk Product 558f7eba | Electronics | $278.65 | 81 | ★ 3.7 | 22 | BULK-0127635c |
| 8040 | Bulk Product 019f162b | Sports & Outdoors | $99.56 | 425 | ★ 2.3 | 36 | BULK-c1776f01 |
| 8041 | Bulk Product c5d5452f | Toys & Games | $349.91 | 29 | ★ 0.2 | 59 | BULK-fc511b47 |
| 8042 | Bulk Product c4b42a74 | Books | $112.14 | 476 | ★ 0.0 | 79 | BULK-6c3562a8 |
| 8043 | Bulk Product 7cd13682 | Clothing | $781.30 | 188 | ★ 0.6 | 98 | BULK-ba2edc3a |
| 8044 | Bulk Product 4a7f8953 | Sports & Outdoors | $501.33 | 389 | ★ 0.1 | 79 | BULK-354a1fd2 |
| 8045 | Bulk Product aec0cabd | Sports & Outdoors | $357.62 | 99 | ★ 0.9 | 68 | BULK-89ec18c5 |
| 8046 | Bulk Product 5bef4070 | Clothing | $531.05 | 441 | ★ 1.2 | 13 | BULK-e611c08c |
| 8047 | Bulk Product c1529565 | Clothing | $905.78 | 389 | ★ 4.1 | 54 | BULK-69292123 |
| 8048 | Bulk Product 787470aa | Books | $514.97 | 290 | ★ 0.8 | 76 | BULK-8dad1d40 |
| 8049 | Bulk Product ca5cdf5f | Electronics | $1,005.18 | 352 | ★ 3.0 | 70 | BULK-9ef2b7ba |
| 8050 | Bulk Product c8e008ba | Home & Garden | $669.47 | 294 | ★ 2.2 | 37 | BULK-cd12dfbf |
| 8051 | Bulk Product 0aaaad07 | Sports & Outdoors | $296.35 | 256 | ★ 3.6 | 11 | BULK-63a60c54 |
| 8052 | Bulk Product 919d0315 | Home & Garden | $396.29 | 193 | ★ 3.6 | 74 | BULK-241d0b37 |
| 8053 | Bulk Product ccdfd4f6 | Clothing | $817.80 | 196 | ★ 0.6 | 59 | BULK-ed2993ae |
| 8054 | Bulk Product 54615788 | Sports & Outdoors | $98.52 | 471 | ★ 2.4 | 43 | BULK-87518474 |
| 8055 | Bulk Product 9a117134 | Electronics | $486.87 | 416 | ★ 2.1 | 19 | BULK-dcfebb51 |
| 8056 | Bulk Product 5e3d039b | Home & Garden | $192.96 | 204 | ★ 3.6 | 21 | BULK-a78fb301 |
| 8057 | Bulk Product a2a59fe0 | Toys & Games | $57.51 | 484 | ★ 3.4 | 30 | BULK-453a49b9 |
| 8058 | Bulk Product d1ca3315 | Books | $380.94 | 323 | ★ 0.5 | 86 | BULK-6dba9db8 |
| 8059 | Bulk Product b42a751d | Toys & Games | $777.95 | 117 | ★ 4.7 | 41 | BULK-378a58e3 |
// 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
};
}