Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8535 | Bulk Product 4eb24f2e | Electronics | $724.68 | 99 | ★ 1.2 | 18 | BULK-bb60060f |
| 8536 | Bulk Product fec5710d | Toys & Games | $577.02 | 76 | ★ 3.3 | 37 | BULK-00bb2274 |
| 8537 | Bulk Product d2a29666 | Clothing | $732.99 | 351 | ★ 1.2 | 25 | BULK-bf8fb6fa |
| 8538 | Bulk Product 34944351 | Home & Garden | $626.43 | 73 | ★ 0.4 | 19 | BULK-5d4a1eee |
| 8539 | Bulk Product 0e4f1b57 | Home & Garden | $69.39 | 298 | ★ 1.7 | 67 | BULK-4513ccfa |
| 8540 | Bulk Product c189238d | Sports & Outdoors | $452.47 | 217 | ★ 4.4 | 3 | BULK-4898947e |
| 8541 | Bulk Product a48c59dd | Toys & Games | $452.05 | 375 | ★ 4.1 | 69 | BULK-06e7ef1c |
| 8542 | Bulk Product 512e986c | Books | $283.64 | 498 | ★ 3.2 | 33 | BULK-d4ccbbb2 |
| 8543 | Bulk Product 8235080c | Toys & Games | $734.26 | 342 | ★ 2.5 | 25 | BULK-14fc9f27 |
| 8544 | Bulk Product 22b70296 | Electronics | $474.87 | 390 | ★ 3.6 | 31 | BULK-e4c5b5cf |
| 8545 | Bulk Product b3a397a9 | Electronics | $807.06 | 48 | ★ 3.6 | 65 | BULK-7896899f |
| 8546 | Bulk Product a9bc795c | Books | $554.90 | 45 | ★ 0.1 | 34 | BULK-45315116 |
| 8547 | Bulk Product 0ff53c06 | Clothing | $420.02 | 128 | ★ 4.3 | 65 | BULK-990e8e60 |
| 8548 | Bulk Product f8e4e50a | Electronics | $851.20 | 179 | ★ 2.0 | 13 | BULK-32bc28de |
| 8549 | Bulk Product 3c72c659 | Electronics | $89.74 | 402 | ★ 4.6 | 7 | BULK-edcb12c7 |
| 8550 | Bulk Product 6a3d2ba3 | Electronics | $713.98 | 337 | ★ 2.4 | 51 | BULK-a8c3402c |
| 8551 | Bulk Product 6cbf511d | Books | $992.07 | 290 | ★ 0.1 | 80 | BULK-1439504f |
| 8552 | Bulk Product 1e56e91a | Books | $687.27 | 310 | ★ 0.7 | 27 | BULK-ee2a2d5e |
| 8553 | Bulk Product f09adb1f | Home & Garden | $890.43 | 8 | ★ 3.4 | 79 | BULK-ffcdfade |
| 8554 | Bulk Product f1a9658d | Home & Garden | $236.67 | 15 | ★ 2.0 | 86 | BULK-7e132a68 |
| 8555 | Bulk Product 7d38fa2e | Books | $441.32 | 240 | ★ 3.6 | 99 | BULK-09a39ded |
| 8556 | Bulk Product af11fa21 | Electronics | $434.18 | 342 | ★ 4.7 | 26 | BULK-fd0b3658 |
| 8557 | Bulk Product 26c870b4 | Clothing | $823.60 | 182 | ★ 3.3 | 3 | BULK-b1c820d1 |
| 8558 | Bulk Product 9599cb1e | Sports & Outdoors | $246.85 | 276 | ★ 2.6 | 12 | BULK-c0d7cb5e |
| 8559 | Bulk Product 272b5728 | Home & Garden | $324.94 | 58 | ★ 4.0 | 81 | BULK-de0b10bc |
// 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
};
}