Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 6260 | Bulk Product 1aa7e025 | Home & Garden | $663.78 | 71 | ★ 5.0 | 77 | BULK-7efc790b |
| 6261 | Bulk Product 986dc20a | Clothing | $608.41 | 44 | ★ 2.7 | 16 | BULK-014f935d |
| 6262 | Bulk Product 78c8d800 | Clothing | $324.61 | 92 | ★ 2.6 | 84 | BULK-652138de |
| 6263 | Bulk Product c2f4de6e | Home & Garden | $608.50 | 51 | ★ 0.0 | 74 | BULK-1b85fa16 |
| 6264 | Bulk Product fca891d4 | Toys & Games | $837.66 | 344 | ★ 2.9 | 85 | BULK-6fd34f67 |
| 6265 | Bulk Product 06110b77 | Clothing | $264.07 | 429 | ★ 0.8 | 43 | BULK-46f6ed70 |
| 6266 | Bulk Product c231e089 | Books | $912.09 | 17 | ★ 3.5 | 99 | BULK-1868cd8b |
| 6267 | Bulk Product 85d35d15 | Clothing | $566.35 | 141 | ★ 0.3 | 61 | BULK-d38767c5 |
| 6268 | Bulk Product eaf0b7fd | Toys & Games | $185.05 | 164 | ★ 2.2 | 65 | BULK-b94508ea |
| 6269 | Bulk Product 1806cdf5 | Electronics | $751.82 | 116 | ★ 1.8 | 65 | BULK-bcaa3035 |
| 6270 | Bulk Product 3ebf75b5 | Sports & Outdoors | $757.33 | 211 | ★ 1.6 | 40 | BULK-f9e7697b |
| 6271 | Bulk Product e89edb71 | Books | $407.98 | 32 | ★ 0.4 | 18 | BULK-9eef5f43 |
| 6272 | Bulk Product 2a371c09 | Electronics | $502.57 | 270 | ★ 3.7 | 98 | BULK-f888a590 |
| 6273 | Bulk Product 1e1df2d2 | Electronics | $523.10 | 92 | ★ 4.8 | 23 | BULK-ef0bfdba |
| 6274 | Bulk Product 6d032294 | Home & Garden | $902.37 | 214 | ★ 4.4 | 77 | BULK-67506c21 |
| 6275 | Bulk Product 81b0f1b0 | Home & Garden | $516.22 | 430 | ★ 1.1 | 95 | BULK-b7a9fc35 |
| 6276 | Bulk Product 304ca6a2 | Toys & Games | $790.75 | 318 | ★ 2.0 | 70 | BULK-14edd002 |
| 6277 | Bulk Product 7adb6760 | Sports & Outdoors | $127.16 | 205 | ★ 2.4 | 61 | BULK-7e40ece9 |
| 6278 | Bulk Product 907c18ff | Clothing | $996.40 | 313 | ★ 4.5 | 9 | BULK-44c6cc71 |
| 6279 | Bulk Product 6d40967e | Books | $273.86 | 210 | ★ 1.9 | 48 | BULK-3a0c879a |
| 6280 | Bulk Product d3852107 | Home & Garden | $494.37 | 39 | ★ 0.2 | 88 | BULK-9d08746a |
| 6281 | Bulk Product d7facc69 | Electronics | $723.38 | 240 | ★ 4.5 | 38 | BULK-b6af0ae9 |
| 6282 | Bulk Product 9d58278d | Sports & Outdoors | $484.27 | 222 | ★ 1.7 | 22 | BULK-5559dc3e |
| 6283 | Bulk Product 98138028 | Clothing | $913.35 | 4 | ★ 2.4 | 7 | BULK-57126cd2 |
| 6284 | Bulk Product 2b1b33a7 | Toys & Games | $589.89 | 258 | ★ 1.2 | 52 | BULK-9fc36210 |
| 6285 | Bulk Product 11327e73 | Books | $432.31 | 429 | ★ 0.1 | 92 | BULK-e0825f4e |
| 6286 | Bulk Product 9f6bb94e | Electronics | $110.70 | 323 | ★ 3.1 | 40 | BULK-8ff474f2 |
| 6287 | Bulk Product d788283d | Home & Garden | $963.66 | 31 | ★ 3.6 | 30 | BULK-ac5c352a |
| 6288 | Bulk Product 5406e2fd | Clothing | $86.78 | 151 | ★ 4.2 | 24 | BULK-1535d3d5 |
| 6289 | Bulk Product 536d3f35 | Toys & Games | $555.80 | 311 | ★ 1.7 | 15 | BULK-254cca24 |
| 6290 | Bulk Product cfb26f97 | Books | $435.98 | 493 | ★ 1.7 | 2 | BULK-0c735dcd |
| 6291 | Bulk Product 2fdbdda6 | Clothing | $510.21 | 332 | ★ 1.7 | 79 | BULK-a11d0586 |
| 6292 | Bulk Product ca88c6bf | Clothing | $14.72 | 19 | ★ 2.0 | 63 | BULK-391b2958 |
| 6293 | Bulk Product 3812d738 | Sports & Outdoors | $645.80 | 293 | ★ 2.2 | 52 | BULK-f3458ee2 |
| 6294 | Bulk Product 034a4a42 | Electronics | $446.79 | 410 | ★ 3.2 | 46 | BULK-39147c36 |
| 6295 | Bulk Product dac6f94b | Clothing | $498.21 | 198 | ★ 4.8 | 81 | BULK-ea952c80 |
| 6296 | Bulk Product ba7b000c | Sports & Outdoors | $238.79 | 382 | ★ 1.0 | 96 | BULK-d5ac3372 |
| 6297 | Bulk Product f602e290 | Clothing | $331.77 | 400 | ★ 3.8 | 46 | BULK-767e0b93 |
| 6298 | Bulk Product f45f48f1 | Electronics | $752.92 | 473 | ★ 2.0 | 41 | BULK-32fb341f |
| 6299 | Bulk Product 86cebcfb | Electronics | $488.20 | 329 | ★ 4.0 | 92 | BULK-afdd9f17 |
| 6300 | Bulk Product 5eeb7fb9 | Electronics | $935.71 | 166 | ★ 2.5 | 45 | BULK-5149a6ad |
| 6301 | Bulk Product 2624fe41 | Sports & Outdoors | $808.28 | 140 | ★ 1.7 | 64 | BULK-bdc55c5d |
| 6302 | Bulk Product 2b5d66c5 | Toys & Games | $214.02 | 272 | ★ 1.9 | 47 | BULK-c635605f |
| 6303 | Bulk Product 24509f4b | Clothing | $33.14 | 415 | ★ 4.1 | 24 | BULK-ad9d28fa |
| 6304 | Bulk Product def083cd | Electronics | $442.95 | 357 | ★ 2.3 | 72 | BULK-ff729633 |
| 6305 | Bulk Product 42fa54c5 | Toys & Games | $863.59 | 393 | ★ 2.8 | 73 | BULK-a373b7e6 |
| 6306 | Bulk Product b9e1d04a | Electronics | $134.24 | 224 | ★ 0.6 | 67 | BULK-51c133f2 |
| 6307 | Bulk Product 544a85ab | Toys & Games | $445.36 | 324 | ★ 4.2 | 80 | BULK-af9191da |
| 6308 | Bulk Product 8de64356 | Books | $516.27 | 144 | ★ 4.5 | 36 | BULK-2f39acf2 |
| 6309 | Bulk Product f97dba9e | Sports & Outdoors | $884.52 | 374 | ★ 1.4 | 72 | BULK-e1410ffc |
// 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
};
}