Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 20610 | Bulk Product 2c720799 | Toys & Games | $739.39 | 82 | ★ 4.5 | 62 | BULK-ed9338f9 |
| 20611 | Bulk Product 04fe27df | Clothing | $1,002.24 | 349 | ★ 3.9 | 29 | BULK-db670cee |
| 20612 | Bulk Product 9fc2ecc9 | Toys & Games | $821.59 | 252 | ★ 1.2 | 36 | BULK-2d364c9c |
| 20613 | Bulk Product f052e1d5 | Sports & Outdoors | $552.21 | 8 | ★ 2.9 | 79 | BULK-c6aac795 |
| 20614 | Bulk Product 5e6a8273 | Clothing | $323.99 | 474 | ★ 3.3 | 56 | BULK-57dbb708 |
| 20615 | Bulk Product 1cb2926a | Sports & Outdoors | $858.76 | 196 | ★ 0.7 | 89 | BULK-f423d9aa |
| 20616 | Bulk Product 46fc6e55 | Books | $472.54 | 470 | ★ 1.0 | 45 | BULK-d9530435 |
| 20617 | Bulk Product b75ac85d | Clothing | $968.41 | 67 | ★ 4.8 | 38 | BULK-8b320c05 |
| 20618 | Bulk Product dbb580cd | Sports & Outdoors | $815.32 | 498 | ★ 2.2 | 49 | BULK-5344ec4f |
| 20619 | Bulk Product cb6e43cb | Electronics | $757.88 | 43 | ★ 4.0 | 59 | BULK-0ed69a8f |
| 20620 | Bulk Product ee364c70 | Electronics | $423.76 | 346 | ★ 1.8 | 75 | BULK-b9654158 |
| 20621 | Bulk Product 00668aab | Home & Garden | $184.09 | 251 | ★ 1.1 | 71 | BULK-a9e07aa4 |
| 20622 | Bulk Product f706bbe8 | Electronics | $717.54 | 488 | ★ 4.2 | 20 | BULK-e2661016 |
| 20623 | Bulk Product 2e564bde | Sports & Outdoors | $723.12 | 242 | ★ 1.2 | 13 | BULK-e7ccfb3e |
| 20624 | Bulk Product 6e0b5985 | Clothing | $991.37 | 263 | ★ 3.5 | 84 | BULK-893d3af0 |
| 20625 | Bulk Product 84a6c371 | Books | $29.35 | 220 | ★ 0.3 | 82 | BULK-a0b4ee39 |
| 20626 | Bulk Product 0f10fe7e | Books | $317.16 | 389 | ★ 2.6 | 46 | BULK-80b6e578 |
| 20627 | Bulk Product 106c1383 | Books | $608.07 | 151 | ★ 4.0 | 24 | BULK-c315ed6d |
| 20628 | Bulk Product 5b047edf | Sports & Outdoors | $283.81 | 302 | ★ 3.2 | 85 | BULK-e14ab14b |
| 20629 | Bulk Product 440b81cf | Clothing | $451.36 | 201 | ★ 4.3 | 11 | BULK-9aafe099 |
| 20630 | Bulk Product 4a7f28da | Toys & Games | $902.19 | 368 | ★ 2.8 | 46 | BULK-6d83d60d |
| 20631 | Bulk Product 9da1bb75 | Sports & Outdoors | $170.19 | 251 | ★ 0.8 | 58 | BULK-abf7f7bf |
| 20632 | Bulk Product 895dae60 | Books | $623.75 | 106 | ★ 3.7 | 0 | BULK-6e5f55ff |
| 20633 | Bulk Product 8a46e2ac | Home & Garden | $305.92 | 354 | ★ 2.6 | 92 | BULK-2cb69381 |
| 20634 | Bulk Product 9b6caf5d | Books | $805.33 | 173 | ★ 4.9 | 88 | BULK-758cad38 |
// 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
};
}