Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8060 | Bulk Product ba89a3bc | Electronics | $188.95 | 136 | ★ 4.8 | 34 | BULK-cc9cd517 |
| 8061 | Bulk Product d65f30bf | Toys & Games | $874.04 | 392 | ★ 2.4 | 48 | BULK-73be2f2e |
| 8062 | Bulk Product 244e6835 | Clothing | $927.50 | 210 | ★ 2.8 | 24 | BULK-7f6a272a |
| 8063 | Bulk Product db39f1be | Sports & Outdoors | $170.24 | 173 | ★ 0.3 | 27 | BULK-0040c701 |
| 8064 | Bulk Product 3fe542a6 | Books | $104.80 | 199 | ★ 3.2 | 93 | BULK-6ee40e06 |
| 8065 | Bulk Product b650a73e | Electronics | $74.11 | 262 | ★ 4.1 | 23 | BULK-7aa5c2d5 |
| 8066 | Bulk Product fef7824c | Sports & Outdoors | $763.73 | 292 | ★ 0.3 | 12 | BULK-e97d5f7a |
| 8067 | Bulk Product b17fcbd9 | Clothing | $960.96 | 249 | ★ 1.6 | 96 | BULK-bd306b75 |
| 8068 | Bulk Product 315adb1b | Toys & Games | $892.06 | 235 | ★ 3.7 | 97 | BULK-ef9bdcc0 |
| 8069 | Bulk Product afe3d67a | Books | $991.74 | 346 | ★ 4.8 | 41 | BULK-1c2939f5 |
| 8070 | Bulk Product 732b62b8 | Books | $577.04 | 308 | ★ 4.2 | 40 | BULK-a8d91822 |
| 8071 | Bulk Product d8800778 | Clothing | $336.48 | 130 | ★ 4.5 | 5 | BULK-6e338a47 |
| 8072 | Bulk Product 0e2696e9 | Home & Garden | $303.94 | 464 | ★ 1.2 | 49 | BULK-511cc4a7 |
| 8073 | Bulk Product 0e7eb122 | Electronics | $933.12 | 271 | ★ 2.4 | 2 | BULK-58258cb8 |
| 8074 | Bulk Product f92db4dc | Electronics | $888.59 | 32 | ★ 4.2 | 4 | BULK-2c587bf8 |
| 8075 | Bulk Product f81f648a | Books | $840.69 | 155 | ★ 5.0 | 34 | BULK-5866e0cd |
| 8076 | Bulk Product 5377ac33 | Clothing | $465.26 | 431 | ★ 1.5 | 46 | BULK-5c32d479 |
| 8077 | Bulk Product cfef9a16 | Home & Garden | $80.79 | 333 | ★ 3.3 | 81 | BULK-e1968554 |
| 8078 | Bulk Product 04909a15 | Sports & Outdoors | $306.09 | 408 | ★ 4.6 | 72 | BULK-10655129 |
| 8079 | Bulk Product e5df4a9f | Books | $659.09 | 345 | ★ 4.3 | 95 | BULK-f995e68d |
| 8080 | Bulk Product f29168a5 | Sports & Outdoors | $891.80 | 88 | ★ 3.2 | 36 | BULK-1c5861f2 |
| 8081 | Bulk Product e5a2c634 | Sports & Outdoors | $59.13 | 448 | ★ 2.0 | 36 | BULK-58a4c401 |
| 8082 | Bulk Product 64236c98 | Sports & Outdoors | $56.81 | 450 | ★ 4.9 | 30 | BULK-99d85049 |
| 8083 | Bulk Product ecafef68 | Books | $149.72 | 309 | ★ 0.7 | 63 | BULK-5d10b8e3 |
| 8084 | Bulk Product 091f1167 | Sports & Outdoors | $674.59 | 468 | ★ 4.3 | 53 | BULK-b30a2190 |
// 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
};
}