Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 12710 | Bulk Product c8e37037 | Books | $613.52 | 144 | ★ 0.5 | 21 | BULK-f98d993a |
| 12711 | Bulk Product cf34af47 | Sports & Outdoors | $859.62 | 296 | ★ 3.0 | 68 | BULK-2172f05d |
| 12712 | Bulk Product 297b4200 | Clothing | $783.31 | 428 | ★ 0.6 | 41 | BULK-532f407e |
| 12713 | Bulk Product 4e9a9745 | Home & Garden | $628.91 | 275 | ★ 0.2 | 78 | BULK-3092028e |
| 12714 | Bulk Product 6bdd662f | Clothing | $219.65 | 98 | ★ 3.7 | 83 | BULK-82e68483 |
| 12715 | Bulk Product 201c01bd | Sports & Outdoors | $103.19 | 257 | ★ 1.4 | 96 | BULK-1702ed68 |
| 12716 | Bulk Product db9d81e0 | Books | $144.34 | 127 | ★ 1.9 | 86 | BULK-209ef429 |
| 12717 | Bulk Product 64fe5bcf | Electronics | $909.82 | 487 | ★ 1.0 | 35 | BULK-b7784a47 |
| 12718 | Bulk Product 1a2eaf07 | Books | $603.64 | 465 | ★ 0.5 | 81 | BULK-473097ea |
| 12719 | Bulk Product f51791b8 | Clothing | $704.43 | 98 | ★ 2.5 | 58 | BULK-86121450 |
| 12720 | Bulk Product 7d8c5037 | Toys & Games | $656.83 | 263 | ★ 3.4 | 68 | BULK-7fa049b5 |
| 12721 | Bulk Product 12009185 | Clothing | $416.20 | 432 | ★ 1.3 | 40 | BULK-174f0955 |
| 12722 | Bulk Product 48730de3 | Sports & Outdoors | $913.24 | 53 | ★ 3.9 | 53 | BULK-81b8184e |
| 12723 | Bulk Product b74dd834 | Sports & Outdoors | $694.02 | 51 | ★ 4.2 | 18 | BULK-f61f0fc2 |
| 12724 | Bulk Product a1f8fbd8 | Books | $314.47 | 169 | ★ 2.6 | 23 | BULK-ec77cdda |
| 12725 | Bulk Product 332227fd | Clothing | $865.99 | 214 | ★ 0.5 | 25 | BULK-5baa1222 |
| 12726 | Bulk Product 3e3ab0e7 | Clothing | $87.34 | 254 | ★ 3.0 | 92 | BULK-d50ddf7c |
| 12727 | Bulk Product cdc55a72 | Electronics | $212.15 | 198 | ★ 2.2 | 55 | BULK-e91b936e |
| 12728 | Bulk Product b459bd9d | Toys & Games | $423.43 | 359 | ★ 2.9 | 26 | BULK-df6f7e30 |
| 12729 | Bulk Product de99bab5 | Home & Garden | $30.23 | 452 | ★ 4.6 | 60 | BULK-ca4245ea |
| 12730 | Bulk Product 6145a33e | Books | $682.81 | 21 | ★ 0.7 | 85 | BULK-3aeef61d |
| 12731 | Bulk Product ab0a0c8c | Books | $715.68 | 205 | ★ 1.6 | 80 | BULK-ffc7ee0b |
| 12732 | Bulk Product 0312f33c | Clothing | $916.32 | 499 | ★ 4.0 | 70 | BULK-c1ace2f2 |
| 12733 | Bulk Product 2d8c5957 | Home & Garden | $634.41 | 466 | ★ 3.7 | 16 | BULK-12e37c4c |
| 12734 | Bulk Product 66038ada | Sports & Outdoors | $187.76 | 297 | ★ 2.2 | 53 | BULK-5f1f8064 |
// 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
};
}