Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8660 | Bulk Product e855886e | Toys & Games | $20.38 | 463 | ★ 4.0 | 26 | BULK-9524c475 |
| 8661 | Bulk Product 67f03861 | Sports & Outdoors | $954.38 | 487 | ★ 4.5 | 1 | BULK-0092c202 |
| 8662 | Bulk Product 83afa2e6 | Toys & Games | $908.66 | 117 | ★ 1.3 | 69 | BULK-3bc7ca1f |
| 8663 | Bulk Product 914ecde5 | Electronics | $95.35 | 318 | ★ 0.0 | 34 | BULK-8d529e2d |
| 8664 | Bulk Product b11138f5 | Electronics | $520.37 | 460 | ★ 1.1 | 28 | BULK-03645cb9 |
| 8665 | Bulk Product b9f66961 | Toys & Games | $670.06 | 437 | ★ 2.1 | 20 | BULK-15f00126 |
| 8666 | Bulk Product 8c7eadd4 | Toys & Games | $856.58 | 289 | ★ 3.8 | 6 | BULK-94875090 |
| 8667 | Bulk Product ebdf083b | Toys & Games | $453.35 | 110 | ★ 5.0 | 19 | BULK-80cf0a1c |
| 8668 | Bulk Product 555c219d | Clothing | $777.36 | 239 | ★ 0.2 | 26 | BULK-3bb15804 |
| 8669 | Bulk Product 41b64041 | Home & Garden | $461.40 | 416 | ★ 1.2 | 25 | BULK-0912fbcf |
| 8670 | Bulk Product 82f0d367 | Sports & Outdoors | $393.90 | 304 | ★ 2.1 | 94 | BULK-a899022f |
| 8671 | Bulk Product db29e0c8 | Toys & Games | $576.77 | 364 | ★ 0.6 | 57 | BULK-74198c9a |
| 8672 | Bulk Product babf1726 | Electronics | $439.73 | 124 | ★ 3.8 | 23 | BULK-a605e2d4 |
| 8673 | Bulk Product 17e29972 | Electronics | $214.06 | 29 | ★ 1.1 | 50 | BULK-ec9ea786 |
| 8674 | Bulk Product 5c321b3c | Home & Garden | $493.34 | 60 | ★ 0.7 | 36 | BULK-911655d8 |
| 8675 | Bulk Product 032ec4c9 | Home & Garden | $763.97 | 365 | ★ 0.7 | 53 | BULK-005b5edf |
| 8676 | Bulk Product b553f6b8 | Toys & Games | $693.54 | 150 | ★ 2.2 | 0 | BULK-044ce6a2 |
| 8677 | Bulk Product cf2eca0a | Sports & Outdoors | $759.13 | 286 | ★ 3.9 | 30 | BULK-18329699 |
| 8678 | Bulk Product 3eb4a9de | Sports & Outdoors | $570.54 | 447 | ★ 3.2 | 93 | BULK-f65c47e7 |
| 8679 | Bulk Product feeba1e9 | Sports & Outdoors | $618.30 | 351 | ★ 1.3 | 51 | BULK-2789def5 |
| 8680 | Bulk Product c3acd847 | Clothing | $810.27 | 309 | ★ 0.3 | 83 | BULK-9e6a2d81 |
| 8681 | Bulk Product 6bc94178 | Clothing | $138.42 | 179 | ★ 2.2 | 96 | BULK-f42be5d5 |
| 8682 | Bulk Product af3b9058 | Clothing | $763.89 | 334 | ★ 2.1 | 70 | BULK-cf586753 |
| 8683 | Bulk Product 70cff6c3 | Toys & Games | $1,002.12 | 246 | ★ 3.3 | 75 | BULK-d03d1195 |
| 8684 | Bulk Product 200536f8 | Sports & Outdoors | $647.67 | 138 | ★ 2.1 | 96 | BULK-fce5e356 |
// 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
};
}