Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 13035 | Bulk Product 26c30a77 | Electronics | $662.92 | 337 | ★ 2.0 | 75 | BULK-918b74b7 |
| 13036 | Bulk Product a05db99a | Electronics | $118.23 | 45 | ★ 1.3 | 52 | BULK-9b17ce99 |
| 13037 | Bulk Product 8670b0fc | Sports & Outdoors | $921.76 | 465 | ★ 2.9 | 68 | BULK-71ed55b3 |
| 13038 | Bulk Product b09d0684 | Clothing | $360.11 | 25 | ★ 3.7 | 32 | BULK-a244ceec |
| 13039 | Bulk Product ea9ef755 | Sports & Outdoors | $443.28 | 277 | ★ 3.6 | 34 | BULK-4b47a4aa |
| 13040 | Bulk Product 7cc2f56f | Books | $107.75 | 13 | ★ 1.6 | 84 | BULK-b7104e28 |
| 13041 | Bulk Product 6dd2bff5 | Toys & Games | $161.95 | 160 | ★ 0.2 | 72 | BULK-b21e5d38 |
| 13042 | Bulk Product ef2d8dd8 | Sports & Outdoors | $706.57 | 347 | ★ 2.8 | 15 | BULK-68142014 |
| 13043 | Bulk Product 60353678 | Home & Garden | $456.98 | 185 | ★ 3.7 | 39 | BULK-6d59f775 |
| 13044 | Bulk Product 10fc1b28 | Toys & Games | $37.40 | 232 | ★ 2.7 | 9 | BULK-805f6807 |
| 13045 | Bulk Product 47dfe2ff | Home & Garden | $187.83 | 397 | ★ 4.6 | 24 | BULK-2b9a944c |
| 13046 | Bulk Product 6824d02f | Clothing | $247.13 | 18 | ★ 1.5 | 51 | BULK-0136d5b2 |
| 13047 | Bulk Product 88386319 | Clothing | $198.53 | 309 | ★ 0.3 | 35 | BULK-a91cd4ce |
| 13048 | Bulk Product f1de9320 | Home & Garden | $33.00 | 308 | ★ 3.6 | 16 | BULK-9b246d58 |
| 13049 | Bulk Product 3aa8a1b2 | Electronics | $610.31 | 273 | ★ 3.4 | 81 | BULK-f964708f |
| 13050 | Bulk Product 64f99e7f | Books | $516.52 | 450 | ★ 4.0 | 33 | BULK-c8eeecc5 |
| 13051 | Bulk Product db7f2ee5 | Books | $671.37 | 303 | ★ 3.1 | 18 | BULK-76a64662 |
| 13052 | Bulk Product f671a871 | Sports & Outdoors | $171.74 | 359 | ★ 2.7 | 50 | BULK-1ae750af |
| 13053 | Bulk Product 63e1e057 | Home & Garden | $338.97 | 338 | ★ 2.0 | 15 | BULK-7f9df34e |
| 13054 | Bulk Product 4856e2f0 | Books | $626.21 | 335 | ★ 2.6 | 97 | BULK-ef481a0e |
| 13055 | Bulk Product f145eccd | Electronics | $168.05 | 388 | ★ 3.0 | 75 | BULK-1af0b6a8 |
| 13056 | Bulk Product 6625cf3d | Toys & Games | $696.43 | 457 | ★ 1.8 | 25 | BULK-cf774eba |
| 13057 | Bulk Product 21ece5be | Electronics | $866.87 | 230 | ★ 3.7 | 23 | BULK-4e26994e |
| 13058 | Bulk Product 51559cd1 | Clothing | $341.47 | 404 | ★ 2.4 | 68 | BULK-76b4862a |
| 13059 | Bulk Product c854c15e | Sports & Outdoors | $560.70 | 380 | ★ 0.9 | 61 | BULK-5da0fdc9 |
// 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
};
}