Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 8510 | Bulk Product 80f3e104 | Home & Garden | $100.30 | 98 | ★ 2.4 | 12 | BULK-fc4fbce0 |
| 8511 | Bulk Product 59123493 | Toys & Games | $304.93 | 127 | ★ 5.0 | 4 | BULK-b7be4cf2 |
| 8512 | Bulk Product 0f816c1f | Clothing | $387.63 | 205 | ★ 0.6 | 86 | BULK-a0c57c4a |
| 8513 | Bulk Product ca1ef35b | Home & Garden | $344.87 | 495 | ★ 1.9 | 47 | BULK-a18e01e8 |
| 8514 | Bulk Product 9b8d0750 | Toys & Games | $71.64 | 453 | ★ 1.8 | 93 | BULK-0949d77f |
| 8515 | Bulk Product 863d86ca | Books | $229.24 | 275 | ★ 0.1 | 33 | BULK-1cb518b2 |
| 8516 | Bulk Product f08e2d83 | Home & Garden | $346.84 | 295 | ★ 2.2 | 52 | BULK-0dc5d935 |
| 8517 | Bulk Product ff940a82 | Books | $513.80 | 322 | ★ 2.1 | 37 | BULK-b264abbe |
| 8518 | Bulk Product 0c16e3cb | Sports & Outdoors | $781.07 | 200 | ★ 0.6 | 51 | BULK-e6b9453e |
| 8519 | Bulk Product 0c033cf9 | Home & Garden | $705.32 | 311 | ★ 2.1 | 21 | BULK-c313489c |
| 8520 | Bulk Product f076344d | Electronics | $431.05 | 254 | ★ 4.1 | 86 | BULK-ca0059af |
| 8521 | Bulk Product 8e71aa29 | Sports & Outdoors | $710.88 | 221 | ★ 1.0 | 6 | BULK-4d6d2389 |
| 8522 | Bulk Product f8a30d22 | Sports & Outdoors | $458.56 | 469 | ★ 1.1 | 14 | BULK-2c574307 |
| 8523 | Bulk Product 8b8ddb77 | Sports & Outdoors | $64.81 | 246 | ★ 4.0 | 63 | BULK-008c2678 |
| 8524 | Bulk Product e999198b | Toys & Games | $885.37 | 447 | ★ 1.1 | 99 | BULK-0140ccf2 |
| 8525 | Bulk Product 6a027193 | Books | $476.30 | 272 | ★ 4.3 | 32 | BULK-37c1e467 |
| 8526 | Bulk Product 69f9ba27 | Clothing | $264.24 | 157 | ★ 1.8 | 59 | BULK-6a5fec77 |
| 8527 | Bulk Product d9ae86e2 | Clothing | $760.90 | 404 | ★ 2.0 | 4 | BULK-68c7da94 |
| 8528 | Bulk Product c15b924d | Books | $888.70 | 373 | ★ 4.1 | 18 | BULK-bd21d735 |
| 8529 | Bulk Product 03a52714 | Toys & Games | $50.11 | 346 | ★ 4.5 | 85 | BULK-64aebd92 |
| 8530 | Bulk Product 1cf25281 | Electronics | $257.59 | 139 | ★ 2.9 | 43 | BULK-2fbdd829 |
| 8531 | Bulk Product 99c7147c | Sports & Outdoors | $264.86 | 95 | ★ 2.8 | 57 | BULK-1546070d |
| 8532 | Bulk Product 918fb3cb | Books | $33.82 | 190 | ★ 1.1 | 32 | BULK-c69e6fc4 |
| 8533 | Bulk Product 9e55164e | Toys & Games | $28.14 | 388 | ★ 4.6 | 4 | BULK-5713afb0 |
| 8534 | Bulk Product e13515d6 | Electronics | $392.31 | 142 | ★ 0.9 | 18 | BULK-54c3e442 |
| 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
};
}