Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 11785 | Bulk Product 1994243c | Sports & Outdoors | $814.09 | 323 | ★ 4.2 | 43 | BULK-28a7a61b |
| 11786 | Bulk Product 5f912469 | Clothing | $546.57 | 104 | ★ 3.2 | 82 | BULK-66f1b921 |
| 11787 | Bulk Product a8d94a91 | Sports & Outdoors | $97.93 | 188 | ★ 1.5 | 29 | BULK-351b3c6f |
| 11788 | Bulk Product 608ee668 | Home & Garden | $731.45 | 93 | ★ 1.3 | 19 | BULK-b74c4a5b |
| 11789 | Bulk Product ffbcca76 | Toys & Games | $332.18 | 335 | ★ 3.1 | 58 | BULK-a16dcda9 |
| 11790 | Bulk Product 3292d131 | Clothing | $197.63 | 449 | ★ 3.2 | 12 | BULK-cee69fad |
| 11791 | Bulk Product db07b7ee | Home & Garden | $586.34 | 365 | ★ 4.7 | 47 | BULK-9984e2e8 |
| 11792 | Bulk Product b62db61a | Home & Garden | $488.52 | 66 | ★ 3.4 | 52 | BULK-3d056d0b |
| 11793 | Bulk Product ccbc445e | Electronics | $547.43 | 197 | ★ 3.8 | 30 | BULK-0d8f4430 |
| 11794 | Bulk Product 642c1f2c | Toys & Games | $689.34 | 342 | ★ 4.9 | 65 | BULK-0b7c3886 |
| 11795 | Bulk Product 0d8ad150 | Books | $102.57 | 72 | ★ 4.0 | 45 | BULK-b4bd2213 |
| 11796 | Bulk Product 6ac71313 | Clothing | $779.90 | 41 | ★ 3.9 | 89 | BULK-5552ff76 |
| 11797 | Bulk Product 9a2e216f | Sports & Outdoors | $164.16 | 351 | ★ 0.2 | 50 | BULK-5c7bb65f |
| 11798 | Bulk Product 0f871e39 | Sports & Outdoors | $864.11 | 239 | ★ 4.5 | 84 | BULK-7711b1cc |
| 11799 | Bulk Product 809b40c1 | Books | $815.97 | 283 | ★ 4.2 | 65 | BULK-ee476982 |
| 11800 | Bulk Product 6ad81330 | Books | $282.38 | 55 | ★ 2.3 | 22 | BULK-640db75e |
| 11801 | Bulk Product 5fbc1eba | Toys & Games | $565.48 | 337 | ★ 1.2 | 90 | BULK-6c959c02 |
| 11802 | Bulk Product f89306d9 | Clothing | $205.07 | 246 | ★ 1.5 | 72 | BULK-06002891 |
| 11803 | Bulk Product 7a1d1c61 | Books | $169.15 | 319 | ★ 0.5 | 51 | BULK-44f840c0 |
| 11804 | Bulk Product e4bc86af | Clothing | $209.48 | 135 | ★ 0.3 | 49 | BULK-5f984dc9 |
| 11805 | Bulk Product 596fdf2a | Toys & Games | $873.39 | 107 | ★ 2.8 | 77 | BULK-2d61e964 |
| 11806 | Bulk Product 024bc0cc | Books | $574.82 | 231 | ★ 1.1 | 94 | BULK-7a106fa5 |
| 11807 | Bulk Product 60ed16db | Clothing | $246.09 | 454 | ★ 1.3 | 50 | BULK-2110b585 |
| 11808 | Bulk Product de71d115 | Electronics | $293.91 | 112 | ★ 4.5 | 71 | BULK-40c3143e |
| 11809 | Bulk Product be6d56f5 | Electronics | $354.89 | 467 | ★ 0.7 | 28 | BULK-65975def |
// 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
};
}