Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 21760 | Bulk Product e05dc45a | Toys & Games | $880.14 | 174 | ★ 1.6 | 36 | BULK-2b19aabd |
| 21761 | Bulk Product be49308f | Toys & Games | $854.42 | 215 | ★ 1.8 | 63 | BULK-58fb61ff |
| 21762 | Bulk Product 751de029 | Clothing | $335.63 | 394 | ★ 3.4 | 55 | BULK-72053a99 |
| 21763 | Bulk Product 841ed72e | Sports & Outdoors | $362.85 | 304 | ★ 4.9 | 36 | BULK-2cfac022 |
| 21764 | Bulk Product f17e8aa2 | Clothing | $867.92 | 478 | ★ 1.1 | 63 | BULK-09dcef9d |
| 21765 | Bulk Product 29709a27 | Books | $389.41 | 440 | ★ 3.8 | 26 | BULK-9defc8d7 |
| 21766 | Bulk Product eb27997a | Books | $343.59 | 247 | ★ 4.4 | 46 | BULK-01e4071c |
| 21767 | Bulk Product 5cf8652a | Toys & Games | $232.82 | 450 | ★ 4.6 | 63 | BULK-37a8b507 |
| 21768 | Bulk Product 30966940 | Toys & Games | $182.64 | 205 | ★ 0.5 | 7 | BULK-d965b879 |
| 21769 | Bulk Product c56feb5e | Clothing | $81.01 | 194 | ★ 2.8 | 48 | BULK-dfac1cf9 |
| 21770 | Bulk Product 3c1fd89d | Sports & Outdoors | $82.64 | 156 | ★ 1.6 | 44 | BULK-168d8fbb |
| 21771 | Bulk Product a29260ed | Electronics | $943.09 | 127 | ★ 3.5 | 30 | BULK-3d50802f |
| 21772 | Bulk Product 6d315c41 | Sports & Outdoors | $186.63 | 86 | ★ 4.3 | 76 | BULK-32ec47cc |
| 21773 | Bulk Product 7cd5c458 | Home & Garden | $751.35 | 324 | ★ 1.9 | 40 | BULK-f731f14b |
| 21774 | Bulk Product 3524bc96 | Home & Garden | $67.98 | 314 | ★ 2.1 | 71 | BULK-113e5730 |
| 21775 | Bulk Product e7c6161a | Electronics | $333.91 | 406 | ★ 2.5 | 29 | BULK-13fd537e |
| 21776 | Bulk Product 122152d5 | Toys & Games | $342.09 | 465 | ★ 5.0 | 27 | BULK-6f2a18fa |
| 21777 | Bulk Product 154c91f1 | Toys & Games | $223.89 | 343 | ★ 0.3 | 61 | BULK-a3812e99 |
| 21778 | Bulk Product 28d1778b | Books | $966.36 | 175 | ★ 1.3 | 80 | BULK-399bd2cc |
| 21779 | Bulk Product 9fd6ae95 | Sports & Outdoors | $940.15 | 342 | ★ 4.8 | 13 | BULK-318d5f31 |
| 21780 | Bulk Product 6755e89a | Clothing | $845.51 | 472 | ★ 3.6 | 67 | BULK-77207b0e |
| 21781 | Bulk Product 48ac1b83 | Sports & Outdoors | $475.14 | 97 | ★ 3.4 | 24 | BULK-fa3c4e8b |
| 21782 | Bulk Product 90070325 | Books | $815.91 | 359 | ★ 4.4 | 44 | BULK-ee6b3753 |
| 21783 | Bulk Product 4eddf898 | Toys & Games | $199.06 | 231 | ★ 4.1 | 51 | BULK-3cdc1d27 |
| 21784 | Bulk Product 99e2ab5f | Home & Garden | $552.35 | 317 | ★ 2.3 | 4 | BULK-88b7c38a |
// 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
};
}