Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17710 | Bulk Product fbfff5df | Toys & Games | $427.62 | 101 | ★ 3.2 | 85 | BULK-f38f5597 |
| 17711 | Bulk Product 619dbc5e | Home & Garden | $441.35 | 104 | ★ 1.8 | 69 | BULK-1a41e6f8 |
| 17712 | Bulk Product e5d8885e | Clothing | $124.84 | 121 | ★ 2.9 | 75 | BULK-36b684af |
| 17713 | Bulk Product f2862fdb | Electronics | $264.41 | 308 | ★ 0.9 | 23 | BULK-80063a32 |
| 17714 | Bulk Product b1e2f642 | Electronics | $677.06 | 168 | ★ 3.3 | 47 | BULK-fd18b165 |
| 17715 | Bulk Product cfcdd464 | Books | $370.29 | 113 | ★ 1.7 | 18 | BULK-7f3fc129 |
| 17716 | Bulk Product 0d763c79 | Toys & Games | $608.15 | 172 | ★ 2.2 | 56 | BULK-bf0f5dde |
| 17717 | Bulk Product f08da7f5 | Books | $17.85 | 294 | ★ 2.6 | 19 | BULK-2130d7e3 |
| 17718 | Bulk Product fbc34052 | Clothing | $53.12 | 4 | ★ 3.6 | 72 | BULK-4a1147f6 |
| 17719 | Bulk Product 36ea0e83 | Clothing | $901.86 | 432 | ★ 0.7 | 46 | BULK-6e863104 |
| 17720 | Bulk Product 1228d4b3 | Clothing | $93.65 | 382 | ★ 5.0 | 92 | BULK-b475d93e |
| 17721 | Bulk Product a5d9a108 | Electronics | $54.31 | 82 | ★ 2.7 | 87 | BULK-688d58d9 |
| 17722 | Bulk Product 03a9deb4 | Books | $911.02 | 477 | ★ 2.8 | 86 | BULK-05506b5c |
| 17723 | Bulk Product 9a70eaac | Home & Garden | $980.99 | 114 | ★ 1.5 | 7 | BULK-13996307 |
| 17724 | Bulk Product 55b97fb4 | Toys & Games | $96.45 | 295 | ★ 3.7 | 65 | BULK-709e9e8c |
| 17725 | Bulk Product 34ee5d59 | Books | $148.35 | 190 | ★ 1.1 | 39 | BULK-20ec0f66 |
| 17726 | Bulk Product 793aff17 | Sports & Outdoors | $898.65 | 245 | ★ 2.6 | 4 | BULK-68cf0df1 |
| 17727 | Bulk Product a2172d74 | Books | $707.11 | 147 | ★ 0.8 | 76 | BULK-705fa563 |
| 17728 | Bulk Product fd3dd862 | Sports & Outdoors | $414.70 | 293 | ★ 1.0 | 71 | BULK-560702b5 |
| 17729 | Bulk Product 719def49 | Electronics | $557.99 | 357 | ★ 3.2 | 17 | BULK-c752f7b4 |
| 17730 | Bulk Product c14d8929 | Home & Garden | $470.05 | 227 | ★ 3.6 | 12 | BULK-f25827df |
| 17731 | Bulk Product c52db8f4 | Electronics | $620.49 | 179 | ★ 1.1 | 22 | BULK-25db8d4d |
| 17732 | Bulk Product 6f0c34c3 | Electronics | $645.61 | 478 | ★ 1.0 | 30 | BULK-3181c350 |
| 17733 | Bulk Product ae2c98be | Electronics | $325.41 | 351 | ★ 2.0 | 55 | BULK-d0cc267b |
| 17734 | Bulk Product f6cddfc7 | Books | $83.43 | 387 | ★ 5.0 | 74 | BULK-109d9c96 |
| 17735 | Bulk Product eedb1793 | Home & Garden | $991.26 | 177 | ★ 2.4 | 6 | BULK-a582bb7f |
| 17736 | Bulk Product 38497f6b | Books | $228.05 | 434 | ★ 0.6 | 59 | BULK-9ed8f234 |
| 17737 | Bulk Product dcfa82d4 | Clothing | $375.32 | 205 | ★ 2.5 | 28 | BULK-975cd2ec |
| 17738 | Bulk Product 9eb7888f | Home & Garden | $663.71 | 495 | ★ 1.1 | 22 | BULK-af0efddd |
| 17739 | Bulk Product 7952027b | Toys & Games | $350.88 | 245 | ★ 2.5 | 15 | BULK-9c168f78 |
| 17740 | Bulk Product 460f344e | Clothing | $130.20 | 61 | ★ 3.6 | 92 | BULK-bf0f37dc |
| 17741 | Bulk Product dc355bc0 | Books | $973.53 | 486 | ★ 2.5 | 79 | BULK-185a6530 |
| 17742 | Bulk Product 0b8e6927 | Sports & Outdoors | $364.09 | 141 | ★ 0.6 | 33 | BULK-c728b7c1 |
| 17743 | Bulk Product 3e9cdabf | Books | $860.17 | 2 | ★ 2.6 | 11 | BULK-ef2ca797 |
| 17744 | Bulk Product 29054d41 | Sports & Outdoors | $763.81 | 416 | ★ 3.7 | 8 | BULK-a80d588e |
| 17745 | Bulk Product 4fdf3071 | Toys & Games | $875.37 | 437 | ★ 4.8 | 25 | BULK-1de86846 |
| 17746 | Bulk Product 03a97f95 | Books | $325.25 | 385 | ★ 1.5 | 86 | BULK-f61c49df |
| 17747 | Bulk Product c298634e | Clothing | $530.03 | 253 | ★ 0.2 | 23 | BULK-2128c67e |
| 17748 | Bulk Product 7e697ba1 | Electronics | $426.64 | 381 | ★ 4.2 | 78 | BULK-42c57865 |
| 17749 | Bulk Product 0d6c4737 | Toys & Games | $462.48 | 408 | ★ 0.9 | 76 | BULK-1359f06b |
| 17750 | Bulk Product faf3dae1 | Toys & Games | $176.83 | 418 | ★ 4.5 | 85 | BULK-913a34bd |
| 17751 | Bulk Product 243ef342 | Clothing | $696.05 | 457 | ★ 4.6 | 9 | BULK-8738073e |
| 17752 | Bulk Product 8b3ca519 | Home & Garden | $902.65 | 241 | ★ 2.6 | 94 | BULK-574ededc |
| 17753 | Bulk Product 73f77c3d | Electronics | $954.70 | 18 | ★ 3.1 | 23 | BULK-79f57b4a |
| 17754 | Bulk Product c2dae8d2 | Sports & Outdoors | $560.17 | 406 | ★ 1.1 | 78 | BULK-36253a4f |
| 17755 | Bulk Product cc24bd41 | Electronics | $518.06 | 140 | ★ 1.0 | 35 | BULK-87acfdab |
| 17756 | Bulk Product 5f0d9fd8 | Home & Garden | $498.96 | 178 | ★ 1.2 | 83 | BULK-f513bb41 |
| 17757 | Bulk Product 5f5f89c7 | Toys & Games | $863.50 | 366 | ★ 0.7 | 89 | BULK-f86d2d3b |
| 17758 | Bulk Product b5267e38 | Sports & Outdoors | $100.23 | 111 | ★ 1.2 | 48 | BULK-edbc947a |
| 17759 | Bulk Product 88a96325 | Toys & Games | $863.21 | 254 | ★ 0.9 | 97 | BULK-5ad7ad6a |
// 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
};
}