Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5960 | Bulk Product 2ecc5221 | Books | $700.47 | 414 | ★ 2.9 | 52 | BULK-cb15b9f8 |
| 5961 | Bulk Product 9b32fd0c | Sports & Outdoors | $585.50 | 89 | ★ 4.4 | 25 | BULK-e2c6054a |
| 5962 | Bulk Product 33cbdbe4 | Clothing | $476.42 | 18 | ★ 0.4 | 96 | BULK-297a7706 |
| 5963 | Bulk Product 42a99537 | Electronics | $518.62 | 179 | ★ 2.4 | 89 | BULK-d3ae86a9 |
| 5964 | Bulk Product 2b82c6ca | Books | $233.46 | 206 | ★ 0.0 | 32 | BULK-312a37db |
| 5965 | Bulk Product 89eae36f | Clothing | $37.03 | 274 | ★ 3.5 | 59 | BULK-8b012cff |
| 5966 | Bulk Product b2996f3f | Clothing | $378.47 | 268 | ★ 3.5 | 52 | BULK-9a4a4f3e |
| 5967 | Bulk Product 2902d60e | Sports & Outdoors | $76.45 | 91 | ★ 0.4 | 50 | BULK-ef7fdd0d |
| 5968 | Bulk Product cb905ee9 | Sports & Outdoors | $18.79 | 262 | ★ 1.9 | 44 | BULK-93ca7d38 |
| 5969 | Bulk Product 501890b4 | Sports & Outdoors | $429.17 | 198 | ★ 4.8 | 78 | BULK-79074747 |
| 5970 | Bulk Product 9cad5624 | Books | $227.34 | 197 | ★ 2.7 | 52 | BULK-402ba46d |
| 5971 | Bulk Product 672654c3 | Books | $572.60 | 402 | ★ 1.4 | 39 | BULK-c3b23e6f |
| 5972 | Bulk Product bfb46f5f | Books | $101.76 | 102 | ★ 3.2 | 38 | BULK-9e6bbf09 |
| 5973 | Bulk Product e715eda5 | Toys & Games | $504.34 | 101 | ★ 3.6 | 9 | BULK-d3803f47 |
| 5974 | Bulk Product b5e1f720 | Books | $373.63 | 372 | ★ 1.8 | 71 | BULK-6ad76b22 |
| 5975 | Bulk Product 5ca98fff | Books | $128.19 | 388 | ★ 4.5 | 77 | BULK-f1e908d4 |
| 5976 | Bulk Product d3408cf3 | Books | $372.97 | 372 | ★ 0.0 | 91 | BULK-41c25717 |
| 5977 | Bulk Product 9d25310d | Sports & Outdoors | $728.66 | 467 | ★ 0.6 | 7 | BULK-83996cd6 |
| 5978 | Bulk Product 1a5d6b94 | Home & Garden | $303.08 | 165 | ★ 1.0 | 63 | BULK-69223dc0 |
| 5979 | Bulk Product c20057bf | Toys & Games | $167.00 | 436 | ★ 2.9 | 70 | BULK-a6780fa1 |
| 5980 | Bulk Product 834ca149 | Toys & Games | $101.20 | 398 | ★ 3.1 | 79 | BULK-6093b040 |
| 5981 | Bulk Product 59b51672 | Clothing | $986.46 | 47 | ★ 2.2 | 26 | BULK-934b4463 |
| 5982 | Bulk Product 7889833e | Toys & Games | $96.55 | 232 | ★ 1.4 | 77 | BULK-2650411f |
| 5983 | Bulk Product 19cea2d5 | Sports & Outdoors | $632.11 | 327 | ★ 0.3 | 35 | BULK-d635a65e |
| 5984 | Bulk Product 2e019445 | Clothing | $147.25 | 207 | ★ 4.1 | 26 | BULK-46298e31 |
// 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
};
}