Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 12560 | Bulk Product 92d57a2a | Sports & Outdoors | $807.58 | 282 | ★ 2.4 | 18 | BULK-a01967b1 |
| 12561 | Bulk Product 08e285e9 | Toys & Games | $892.74 | 24 | ★ 1.7 | 65 | BULK-a9dbda5f |
| 12562 | Bulk Product 41491195 | Clothing | $972.99 | 459 | ★ 4.4 | 32 | BULK-b3244fd2 |
| 12563 | Bulk Product b8724056 | Toys & Games | $778.30 | 375 | ★ 4.9 | 57 | BULK-6ecd9461 |
| 12564 | Bulk Product 006d27ba | Books | $968.88 | 336 | ★ 2.4 | 96 | BULK-3e6630b9 |
| 12565 | Bulk Product 5480fbab | Books | $670.26 | 325 | ★ 0.1 | 29 | BULK-56a6d497 |
| 12566 | Bulk Product 28feeaec | Clothing | $293.03 | 241 | ★ 2.5 | 78 | BULK-67d8fa29 |
| 12567 | Bulk Product c9cec84e | Clothing | $342.41 | 321 | ★ 4.6 | 31 | BULK-9b224257 |
| 12568 | Bulk Product 7f3fe303 | Books | $625.23 | 417 | ★ 3.2 | 57 | BULK-7ff41028 |
| 12569 | Bulk Product e808205b | Toys & Games | $220.47 | 68 | ★ 3.6 | 76 | BULK-271a8347 |
| 12570 | Bulk Product 377af80e | Toys & Games | $885.86 | 250 | ★ 0.8 | 51 | BULK-25090672 |
| 12571 | Bulk Product c603a653 | Home & Garden | $384.55 | 392 | ★ 2.9 | 16 | BULK-2e938a3d |
| 12572 | Bulk Product e0fa2ce5 | Sports & Outdoors | $285.63 | 261 | ★ 1.3 | 12 | BULK-2a8e5c60 |
| 12573 | Bulk Product b598ff63 | Sports & Outdoors | $218.96 | 111 | ★ 1.9 | 3 | BULK-d67a538b |
| 12574 | Bulk Product 54c69b42 | Toys & Games | $982.15 | 170 | ★ 4.5 | 68 | BULK-af458ecb |
| 12575 | Bulk Product b26801a4 | Clothing | $259.04 | 96 | ★ 1.1 | 57 | BULK-5259079d |
| 12576 | Bulk Product c27622a4 | Sports & Outdoors | $12.92 | 237 | ★ 1.0 | 7 | BULK-d10c1dcc |
| 12577 | Bulk Product 0fc1daa1 | Books | $260.62 | 81 | ★ 4.2 | 83 | BULK-5e938c86 |
| 12578 | Bulk Product 5681d034 | Sports & Outdoors | $525.74 | 59 | ★ 2.0 | 41 | BULK-830927ea |
| 12579 | Bulk Product a56867bb | Clothing | $606.25 | 472 | ★ 1.6 | 63 | BULK-10f120e6 |
| 12580 | Bulk Product f725c62d | Clothing | $292.35 | 214 | ★ 0.2 | 99 | BULK-1eaed2dd |
| 12581 | Bulk Product 40de0cc4 | Electronics | $240.65 | 397 | ★ 2.4 | 37 | BULK-cc093b3c |
| 12582 | Bulk Product 265ebd15 | Books | $781.29 | 278 | ★ 1.3 | 97 | BULK-1629a05c |
| 12583 | Bulk Product 683daf10 | Home & Garden | $835.84 | 444 | ★ 0.2 | 64 | BULK-e61d2179 |
| 12584 | Bulk Product cbbacf88 | Sports & Outdoors | $886.55 | 418 | ★ 3.9 | 19 | BULK-cb177b05 |
| 12585 | Bulk Product 5419283f | Clothing | $985.15 | 321 | ★ 3.2 | 8 | BULK-dc8ec625 |
| 12586 | Bulk Product c6e009e8 | Home & Garden | $846.25 | 161 | ★ 4.0 | 91 | BULK-d0d5ca69 |
| 12587 | Bulk Product 682e51ae | Electronics | $736.83 | 212 | ★ 3.1 | 81 | BULK-2647832a |
| 12588 | Bulk Product 41740d9f | Clothing | $701.95 | 436 | ★ 3.8 | 11 | BULK-ca4a7046 |
| 12589 | Bulk Product 67df0fdc | Home & Garden | $390.94 | 485 | ★ 2.5 | 76 | BULK-15b2e1be |
| 12590 | Bulk Product b640276e | Books | $332.64 | 382 | ★ 4.0 | 39 | BULK-e523733f |
| 12591 | Bulk Product 81c1b1ad | Toys & Games | $443.56 | 427 | ★ 4.9 | 68 | BULK-9c9e2e49 |
| 12592 | Bulk Product 151ad4e4 | Clothing | $852.58 | 69 | ★ 3.4 | 41 | BULK-289d58d9 |
| 12593 | Bulk Product cffd747a | Books | $14.55 | 87 | ★ 4.3 | 65 | BULK-551b1464 |
| 12594 | Bulk Product f26f8eee | Electronics | $490.01 | 151 | ★ 2.0 | 37 | BULK-b279e5d0 |
| 12595 | Bulk Product 9a57847e | Electronics | $434.22 | 73 | ★ 1.4 | 55 | BULK-7ea3e1e0 |
| 12596 | Bulk Product b058004a | Electronics | $451.39 | 477 | ★ 0.3 | 30 | BULK-3e070b4f |
| 12597 | Bulk Product ba4122e8 | Home & Garden | $968.16 | 383 | ★ 2.1 | 56 | BULK-9f2fd2f3 |
| 12598 | Bulk Product 616d3586 | Home & Garden | $854.04 | 406 | ★ 2.8 | 63 | BULK-2c09158f |
| 12599 | Bulk Product 01f759a9 | Home & Garden | $643.22 | 105 | ★ 2.3 | 53 | BULK-978032aa |
| 12600 | Bulk Product 8e9af764 | Sports & Outdoors | $613.38 | 236 | ★ 4.5 | 43 | BULK-c68354c9 |
| 12601 | Bulk Product e7fa3635 | Electronics | $88.04 | 187 | ★ 1.4 | 59 | BULK-818b7767 |
| 12602 | Bulk Product 9c3838d2 | Electronics | $248.62 | 297 | ★ 3.9 | 3 | BULK-81e8d130 |
| 12603 | Bulk Product 897aa55f | Clothing | $288.47 | 90 | ★ 1.9 | 73 | BULK-8561674d |
| 12604 | Bulk Product b756f36e | Home & Garden | $749.20 | 430 | ★ 3.3 | 25 | BULK-2efc15e4 |
| 12605 | Bulk Product 08f2a3e6 | Sports & Outdoors | $958.84 | 212 | ★ 0.7 | 12 | BULK-4f278cb7 |
| 12606 | Bulk Product cbf7900d | Clothing | $583.91 | 185 | ★ 0.9 | 73 | BULK-97369f2c |
| 12607 | Bulk Product 479729df | Clothing | $913.74 | 10 | ★ 3.8 | 73 | BULK-4f2d98ef |
| 12608 | Bulk Product ce0f355f | Sports & Outdoors | $343.55 | 30 | ★ 2.7 | 35 | BULK-310f8a7d |
| 12609 | Bulk Product 79e73bd8 | Sports & Outdoors | $226.34 | 387 | ★ 3.0 | 57 | BULK-36aae316 |
// 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
};
}