Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 6810 | Bulk Product edd9cd32 | Books | $806.62 | 145 | ★ 3.2 | 94 | BULK-986ddd8d |
| 6811 | Bulk Product 22076098 | Clothing | $683.62 | 407 | ★ 1.6 | 70 | BULK-29411cd3 |
| 6812 | Bulk Product 119f77f0 | Clothing | $477.76 | 232 | ★ 0.5 | 14 | BULK-f73501a0 |
| 6813 | Bulk Product 2043a800 | Sports & Outdoors | $193.14 | 241 | ★ 1.7 | 82 | BULK-b615a69e |
| 6814 | Bulk Product cf3fe8de | Books | $384.30 | 421 | ★ 4.4 | 86 | BULK-a287d026 |
| 6815 | Bulk Product 8629c276 | Home & Garden | $585.26 | 362 | ★ 0.7 | 39 | BULK-85d99a03 |
| 6816 | Bulk Product 4ffedbc7 | Toys & Games | $107.47 | 360 | ★ 3.7 | 92 | BULK-cfb24d0f |
| 6817 | Bulk Product 7024d887 | Sports & Outdoors | $816.68 | 348 | ★ 2.5 | 52 | BULK-a6e3e53f |
| 6818 | Bulk Product 006a0b98 | Sports & Outdoors | $101.05 | 164 | ★ 0.3 | 17 | BULK-289807ec |
| 6819 | Bulk Product d19fd3e0 | Home & Garden | $872.86 | 32 | ★ 2.5 | 26 | BULK-cae86967 |
| 6820 | Bulk Product e4b91178 | Books | $435.11 | 376 | ★ 2.2 | 76 | BULK-44f8999e |
| 6821 | Bulk Product 0830e3ea | Sports & Outdoors | $784.39 | 484 | ★ 3.1 | 71 | BULK-4170fa41 |
| 6822 | Bulk Product c7af291c | Clothing | $122.01 | 308 | ★ 2.8 | 88 | BULK-eb85fd93 |
| 6823 | Bulk Product 809399fa | Home & Garden | $830.57 | 203 | ★ 3.0 | 45 | BULK-770c1ab2 |
| 6824 | Bulk Product cfefa471 | Toys & Games | $656.70 | 115 | ★ 2.2 | 17 | BULK-90776875 |
| 6825 | Bulk Product 1f9dad43 | Clothing | $865.43 | 308 | ★ 0.0 | 13 | BULK-d9d20da1 |
| 6826 | Bulk Product 2500c724 | Electronics | $981.15 | 325 | ★ 3.3 | 16 | BULK-261c10cf |
| 6827 | Bulk Product 743c3c11 | Toys & Games | $961.14 | 440 | ★ 4.9 | 27 | BULK-03171187 |
| 6828 | Bulk Product ee4f2dcc | Sports & Outdoors | $665.34 | 95 | ★ 0.2 | 51 | BULK-8bfb55bd |
| 6829 | Bulk Product a2b9abbd | Home & Garden | $999.68 | 169 | ★ 0.9 | 43 | BULK-ba9ea684 |
| 6830 | Bulk Product 79e8a712 | Toys & Games | $852.87 | 191 | ★ 2.0 | 84 | BULK-663f5b5d |
| 6831 | Bulk Product 98696a9a | Electronics | $432.98 | 268 | ★ 4.6 | 85 | BULK-b7d4f86f |
| 6832 | Bulk Product d266de72 | Clothing | $27.16 | 348 | ★ 1.4 | 30 | BULK-6ffd6c75 |
| 6833 | Bulk Product 726aa53d | Books | $991.51 | 487 | ★ 4.4 | 9 | BULK-d8bc9d70 |
| 6834 | Bulk Product c22cbfd4 | Electronics | $288.08 | 168 | ★ 3.9 | 9 | BULK-9bb93069 |
| 6835 | Bulk Product 47b5263b | Electronics | $131.93 | 36 | ★ 2.5 | 5 | BULK-63c73f76 |
| 6836 | Bulk Product 70d1b5af | Sports & Outdoors | $667.51 | 435 | ★ 2.2 | 8 | BULK-5dec1793 |
| 6837 | Bulk Product d546be2f | Electronics | $144.96 | 319 | ★ 3.4 | 3 | BULK-81b6d904 |
| 6838 | Bulk Product fffe6dfe | Toys & Games | $492.76 | 479 | ★ 4.4 | 63 | BULK-e6ef073e |
| 6839 | Bulk Product 3d6b3363 | Home & Garden | $126.29 | 167 | ★ 3.5 | 24 | BULK-de6ebfe0 |
| 6840 | Bulk Product 906fa89e | Electronics | $96.25 | 169 | ★ 4.8 | 75 | BULK-741469a2 |
| 6841 | Bulk Product ccd35da0 | Sports & Outdoors | $318.91 | 439 | ★ 0.5 | 72 | BULK-adcb958a |
| 6842 | Bulk Product 7c93f053 | Books | $262.62 | 499 | ★ 4.2 | 83 | BULK-5e76d020 |
| 6843 | Bulk Product 0c8a00c3 | Toys & Games | $461.58 | 418 | ★ 0.8 | 11 | BULK-d1d83c6c |
| 6844 | Bulk Product 56d1bff9 | Electronics | $642.64 | 482 | ★ 3.5 | 20 | BULK-d1d54505 |
| 6845 | Bulk Product 7e1eb48b | Electronics | $577.14 | 488 | ★ 2.7 | 12 | BULK-8ae88e6e |
| 6846 | Bulk Product 89fa9023 | Home & Garden | $978.30 | 117 | ★ 0.1 | 85 | BULK-7f38e59f |
| 6847 | Bulk Product fb28a946 | Books | $586.29 | 472 | ★ 2.5 | 24 | BULK-a5ee6a5f |
| 6848 | Bulk Product 70e2bdd4 | Clothing | $519.44 | 479 | ★ 2.5 | 89 | BULK-9275969c |
| 6849 | Bulk Product acc0f6dd | Electronics | $883.15 | 497 | ★ 2.1 | 34 | BULK-5d051ab7 |
| 6850 | Bulk Product 834b4d9d | Sports & Outdoors | $605.05 | 452 | ★ 2.8 | 21 | BULK-edaaba7a |
| 6851 | Bulk Product 340f5c22 | Clothing | $133.93 | 76 | ★ 2.8 | 33 | BULK-7401bbfd |
| 6852 | Bulk Product 08a400e1 | Sports & Outdoors | $231.10 | 177 | ★ 4.5 | 14 | BULK-740619c2 |
| 6853 | Bulk Product 2b58f633 | Sports & Outdoors | $371.78 | 288 | ★ 2.2 | 46 | BULK-b246d496 |
| 6854 | Bulk Product 98a62360 | Sports & Outdoors | $29.46 | 129 | ★ 4.9 | 7 | BULK-1224879b |
| 6855 | Bulk Product bea195be | Books | $885.95 | 323 | ★ 2.6 | 6 | BULK-afafb0b2 |
| 6856 | Bulk Product 3b2fe2c9 | Books | $341.34 | 443 | ★ 2.7 | 31 | BULK-7a0ff1e8 |
| 6857 | Bulk Product 78452ae9 | Home & Garden | $187.32 | 329 | ★ 2.7 | 60 | BULK-d920eb0b |
| 6858 | Bulk Product 3f1d1464 | Sports & Outdoors | $841.74 | 88 | ★ 2.0 | 52 | BULK-51914cd9 |
| 6859 | Bulk Product de5db1dd | Electronics | $447.49 | 66 | ★ 2.9 | 99 | BULK-2e1954d0 |
// 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
};
}