Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 13860 | Bulk Product 80ccfc95 | Sports & Outdoors | $60.32 | 364 | ★ 1.6 | 22 | BULK-17f5b899 |
| 13861 | Bulk Product 617cf603 | Sports & Outdoors | $44.57 | 497 | ★ 1.8 | 45 | BULK-bbb870ce |
| 13862 | Bulk Product 355e43fd | Home & Garden | $326.15 | 133 | ★ 2.0 | 34 | BULK-fde96166 |
| 13863 | Bulk Product a255bfd9 | Toys & Games | $655.96 | 417 | ★ 0.3 | 39 | BULK-ee7b7449 |
| 13864 | Bulk Product c235568c | Toys & Games | $946.21 | 87 | ★ 1.7 | 40 | BULK-3267fe72 |
| 13865 | Bulk Product 804c072a | Books | $185.77 | 461 | ★ 1.5 | 9 | BULK-0df3a9bc |
| 13866 | Bulk Product 7265478f | Books | $654.74 | 220 | ★ 0.1 | 73 | BULK-cf02278a |
| 13867 | Bulk Product 1f98b93f | Books | $596.54 | 243 | ★ 2.9 | 54 | BULK-40f8dcba |
| 13868 | Bulk Product 000871d8 | Sports & Outdoors | $148.50 | 151 | ★ 3.4 | 23 | BULK-a959e9b2 |
| 13869 | Bulk Product bf8afe46 | Sports & Outdoors | $630.77 | 188 | ★ 0.6 | 70 | BULK-4efe7fb5 |
| 13870 | Bulk Product e8cb7d87 | Electronics | $576.12 | 253 | ★ 3.5 | 69 | BULK-1cb53c22 |
| 13871 | Bulk Product edc936cf | Electronics | $990.78 | 460 | ★ 3.8 | 22 | BULK-510f13fd |
| 13872 | Bulk Product d7b8a7a8 | Home & Garden | $14.88 | 434 | ★ 0.2 | 8 | BULK-b71049e4 |
| 13873 | Bulk Product fdb2b16c | Sports & Outdoors | $224.17 | 429 | ★ 1.6 | 91 | BULK-32c2e448 |
| 13874 | Bulk Product fe8a149a | Toys & Games | $786.20 | 267 | ★ 2.9 | 68 | BULK-339da6c0 |
| 13875 | Bulk Product c3413daa | Sports & Outdoors | $821.36 | 451 | ★ 0.4 | 52 | BULK-24e04570 |
| 13876 | Bulk Product cb39fe1d | Home & Garden | $777.35 | 267 | ★ 3.9 | 46 | BULK-ef5ff991 |
| 13877 | Bulk Product 51383108 | Electronics | $461.09 | 354 | ★ 1.1 | 76 | BULK-88f9bc56 |
| 13878 | Bulk Product eaf0e28d | Electronics | $210.31 | 464 | ★ 3.5 | 26 | BULK-fcf95f65 |
| 13879 | Bulk Product ab0b4685 | Electronics | $794.59 | 494 | ★ 0.9 | 0 | BULK-b603999a |
| 13880 | Bulk Product 35cc0820 | Clothing | $767.35 | 187 | ★ 3.9 | 56 | BULK-ed45adee |
| 13881 | Bulk Product 30b15971 | Sports & Outdoors | $987.38 | 251 | ★ 4.4 | 12 | BULK-04bfa36f |
| 13882 | Bulk Product 126329fa | Sports & Outdoors | $386.82 | 84 | ★ 4.6 | 48 | BULK-75e887c8 |
| 13883 | Bulk Product 288bd7d7 | Clothing | $865.77 | 205 | ★ 1.9 | 29 | BULK-afaa6d63 |
| 13884 | Bulk Product c228a1c1 | Clothing | $392.79 | 40 | ★ 3.8 | 31 | BULK-f93fae0b |
// 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
};
}