Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 10085 | Bulk Product b6fc3848 | Electronics | $814.27 | 107 | ★ 2.2 | 37 | BULK-b7bf3c11 |
| 10086 | Bulk Product 5d71129c | Electronics | $620.98 | 426 | ★ 0.8 | 97 | BULK-84380806 |
| 10087 | Bulk Product 1dc0bbe2 | Home & Garden | $401.80 | 341 | ★ 2.6 | 22 | BULK-16daf0da |
| 10088 | Bulk Product e7f7c254 | Books | $986.57 | 145 | ★ 4.5 | 64 | BULK-4742b3be |
| 10089 | Bulk Product d4773c00 | Sports & Outdoors | $932.30 | 379 | ★ 3.6 | 46 | BULK-37cffd59 |
| 10090 | Bulk Product 3de70a78 | Clothing | $740.41 | 70 | ★ 4.6 | 69 | BULK-2ed3b158 |
| 10091 | Bulk Product aa6ca0a6 | Toys & Games | $792.99 | 295 | ★ 1.1 | 4 | BULK-9c2012bf |
| 10092 | Bulk Product 519a8dd2 | Electronics | $945.99 | 294 | ★ 4.9 | 27 | BULK-a4e915b9 |
| 10093 | Bulk Product 04974992 | Clothing | $776.98 | 335 | ★ 0.1 | 60 | BULK-5bd002df |
| 10094 | Bulk Product fdbdc967 | Electronics | $219.10 | 65 | ★ 4.4 | 2 | BULK-f0ab004c |
| 10095 | Bulk Product 6bd39f96 | Electronics | $659.33 | 247 | ★ 2.5 | 72 | BULK-1fcf3a58 |
| 10096 | Bulk Product aa7f4d91 | Books | $434.90 | 79 | ★ 1.5 | 74 | BULK-45c577b8 |
| 10097 | Bulk Product 8b35986d | Home & Garden | $893.97 | 451 | ★ 0.6 | 32 | BULK-bcfb0840 |
| 10098 | Bulk Product 1de29edc | Toys & Games | $895.80 | 394 | ★ 1.2 | 62 | BULK-f336ca9d |
| 10099 | Bulk Product 707b863b | Clothing | $868.84 | 265 | ★ 2.6 | 63 | BULK-e3844f18 |
| 10100 | Bulk Product 71b484d5 | Sports & Outdoors | $562.00 | 139 | ★ 0.2 | 7 | BULK-e2b423bd |
| 10101 | Bulk Product 89351264 | Toys & Games | $551.60 | 470 | ★ 1.6 | 68 | BULK-46b19232 |
| 10102 | Bulk Product 6ca89472 | Sports & Outdoors | $707.09 | 391 | ★ 0.4 | 21 | BULK-8a5d56f3 |
| 10103 | Bulk Product 71c340d4 | Sports & Outdoors | $154.05 | 112 | ★ 2.0 | 60 | BULK-ad65038d |
| 10104 | Bulk Product f54bf9d0 | Books | $757.56 | 419 | ★ 0.0 | 87 | BULK-882a473b |
| 10105 | Bulk Product 629869e8 | Books | $752.35 | 250 | ★ 4.7 | 81 | BULK-2d3d01dd |
| 10106 | Bulk Product a94421f4 | Home & Garden | $271.25 | 80 | ★ 3.2 | 55 | BULK-f3a2a0a2 |
| 10107 | Bulk Product c9d370b8 | Electronics | $512.35 | 1 | ★ 3.4 | 62 | BULK-54e077d9 |
| 10108 | Bulk Product a4df1b59 | Books | $541.98 | 392 | ★ 2.5 | 84 | BULK-6f4d3ddf |
| 10109 | Bulk Product b469df8c | Toys & Games | $156.83 | 160 | ★ 4.0 | 46 | BULK-12bac3ca |
// 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
};
}