Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 7385 | Bulk Product d789643e | Sports & Outdoors | $30.60 | 18 | ★ 1.2 | 4 | BULK-d36c4b65 |
| 7386 | Bulk Product 63d00d41 | Clothing | $195.65 | 97 | ★ 1.1 | 85 | BULK-95d7cbae |
| 7387 | Bulk Product 4c8db492 | Books | $703.35 | 450 | ★ 0.8 | 92 | BULK-567e9f72 |
| 7388 | Bulk Product f27e709a | Clothing | $852.85 | 335 | ★ 0.1 | 6 | BULK-0d0c37c8 |
| 7389 | Bulk Product 8836d61d | Books | $496.42 | 466 | ★ 2.2 | 41 | BULK-b2dd9d19 |
| 7390 | Bulk Product e21b62c4 | Clothing | $435.87 | 74 | ★ 1.5 | 40 | BULK-16c6af26 |
| 7391 | Bulk Product 35b1c436 | Electronics | $265.95 | 287 | ★ 2.5 | 58 | BULK-1e30deb2 |
| 7392 | Bulk Product 6dfd48fd | Clothing | $132.01 | 447 | ★ 3.8 | 47 | BULK-2fa5e119 |
| 7393 | Bulk Product 0e28ec93 | Books | $13.16 | 349 | ★ 3.2 | 43 | BULK-92ad6fb6 |
| 7394 | Bulk Product 3d356d17 | Sports & Outdoors | $759.99 | 350 | ★ 4.6 | 23 | BULK-8abeb2a2 |
| 7395 | Bulk Product 7978f98f | Toys & Games | $47.31 | 193 | ★ 4.4 | 70 | BULK-ea7e76a4 |
| 7396 | Bulk Product 0af94598 | Sports & Outdoors | $553.47 | 285 | ★ 3.8 | 44 | BULK-c41cc1d1 |
| 7397 | Bulk Product 2d34ff2d | Sports & Outdoors | $399.66 | 387 | ★ 2.1 | 47 | BULK-fa0b4297 |
| 7398 | Bulk Product 7ff5ff2f | Clothing | $116.84 | 205 | ★ 4.2 | 48 | BULK-15c19575 |
| 7399 | Bulk Product 5de0bccf | Books | $947.81 | 429 | ★ 3.5 | 67 | BULK-81a4d1c6 |
| 7400 | Bulk Product 794dd3dd | Electronics | $665.06 | 186 | ★ 0.0 | 87 | BULK-5932bb8e |
| 7401 | Bulk Product b7b4e98d | Sports & Outdoors | $366.39 | 475 | ★ 0.8 | 49 | BULK-28844236 |
| 7402 | Bulk Product 09e07366 | Books | $448.18 | 129 | ★ 0.2 | 64 | BULK-60e25420 |
| 7403 | Bulk Product 58d8e0f9 | Toys & Games | $38.42 | 69 | ★ 0.7 | 28 | BULK-39c8dd71 |
| 7404 | Bulk Product 7ea029d4 | Home & Garden | $900.28 | 126 | ★ 2.5 | 97 | BULK-13f7701f |
| 7405 | Bulk Product 2bf1cdfe | Toys & Games | $515.83 | 248 | ★ 4.7 | 46 | BULK-c5695d16 |
| 7406 | Bulk Product 4b663ce6 | Clothing | $782.55 | 116 | ★ 3.6 | 12 | BULK-92d4657f |
| 7407 | Bulk Product 61d73bd6 | Electronics | $939.31 | 416 | ★ 1.4 | 84 | BULK-60d4fb85 |
| 7408 | Bulk Product c5e85de0 | Clothing | $97.15 | 396 | ★ 5.0 | 46 | BULK-ec73e035 |
| 7409 | Bulk Product d1f494ba | Electronics | $734.41 | 231 | ★ 1.2 | 14 | BULK-621a95ef |
// 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
};
}