Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5760 | Bulk Product ebf34d37 | Electronics | $937.56 | 332 | ★ 3.6 | 18 | BULK-9389f6be |
| 5761 | Bulk Product 71401e3b | Electronics | $35.16 | 463 | ★ 2.5 | 39 | BULK-3042a837 |
| 5762 | Bulk Product 6aab2cbc | Books | $534.23 | 385 | ★ 2.0 | 78 | BULK-b6051eee |
| 5763 | Bulk Product 5a68be95 | Home & Garden | $277.12 | 161 | ★ 0.7 | 1 | BULK-67a46d33 |
| 5764 | Bulk Product cc4ac898 | Clothing | $625.67 | 282 | ★ 2.9 | 4 | BULK-16a6b1a4 |
| 5765 | Bulk Product e6dd8ba3 | Sports & Outdoors | $240.94 | 444 | ★ 5.0 | 85 | BULK-c7783295 |
| 5766 | Bulk Product db0a3176 | Sports & Outdoors | $623.67 | 249 | ★ 0.8 | 29 | BULK-fbd53c3d |
| 5767 | Bulk Product f8184a55 | Clothing | $900.43 | 130 | ★ 2.7 | 16 | BULK-3c1ccfb0 |
| 5768 | Bulk Product e3676036 | Books | $286.97 | 326 | ★ 0.2 | 40 | BULK-6843a48a |
| 5769 | Bulk Product 9cb4c013 | Sports & Outdoors | $157.08 | 365 | ★ 4.8 | 38 | BULK-28371cda |
| 5770 | Bulk Product 90c332c1 | Electronics | $910.54 | 229 | ★ 0.6 | 90 | BULK-cf652a6b |
| 5771 | Bulk Product 9c7432bd | Electronics | $426.61 | 159 | ★ 2.4 | 92 | BULK-975496cc |
| 5772 | Bulk Product 419d87c9 | Sports & Outdoors | $874.92 | 311 | ★ 0.5 | 91 | BULK-a2bc7ab6 |
| 5773 | Bulk Product 9325103d | Clothing | $709.57 | 422 | ★ 4.0 | 51 | BULK-db79525c |
| 5774 | Bulk Product ba55a882 | Sports & Outdoors | $934.75 | 491 | ★ 3.0 | 32 | BULK-956b926d |
| 5775 | Bulk Product 5d492eed | Electronics | $880.83 | 280 | ★ 2.2 | 67 | BULK-7968b109 |
| 5776 | Bulk Product 6a97dabd | Books | $282.72 | 48 | ★ 4.7 | 18 | BULK-50428469 |
| 5777 | Bulk Product 42f69854 | Electronics | $730.33 | 429 | ★ 0.2 | 40 | BULK-dadf960b |
| 5778 | Bulk Product 722153cf | Sports & Outdoors | $742.30 | 135 | ★ 3.5 | 96 | BULK-7d4fe3f2 |
| 5779 | Bulk Product 72d89874 | Toys & Games | $425.79 | 317 | ★ 3.3 | 34 | BULK-20ab58d9 |
| 5780 | Bulk Product d54d4d00 | Books | $341.99 | 269 | ★ 2.7 | 25 | BULK-09a81da3 |
| 5781 | Bulk Product 2c3e91f7 | Books | $270.25 | 350 | ★ 2.4 | 14 | BULK-0135453d |
| 5782 | Bulk Product 23f67e98 | Electronics | $185.58 | 94 | ★ 4.5 | 78 | BULK-e9f02881 |
| 5783 | Bulk Product cac6f696 | Clothing | $373.36 | 49 | ★ 2.8 | 4 | BULK-a945e596 |
| 5784 | Bulk Product 40791b06 | Clothing | $558.06 | 191 | ★ 0.8 | 45 | BULK-c8fdf9b7 |
| 5785 | Bulk Product 033cf07f | Sports & Outdoors | $378.11 | 464 | ★ 1.0 | 94 | BULK-ab040536 |
| 5786 | Bulk Product ea6ed801 | Books | $276.57 | 327 | ★ 3.4 | 61 | BULK-f62a7020 |
| 5787 | Bulk Product 385d7313 | Toys & Games | $700.78 | 271 | ★ 3.4 | 14 | BULK-6fbbee8e |
| 5788 | Bulk Product ad960107 | Electronics | $130.15 | 363 | ★ 0.4 | 92 | BULK-1d6e4fd8 |
| 5789 | Bulk Product ce4d6ab9 | Home & Garden | $212.80 | 248 | ★ 1.4 | 25 | BULK-22405300 |
| 5790 | Bulk Product 57a64487 | Books | $131.23 | 378 | ★ 4.0 | 10 | BULK-b84a1c13 |
| 5791 | Bulk Product 9653bcec | Sports & Outdoors | $254.91 | 165 | ★ 2.9 | 46 | BULK-b8fd4c1e |
| 5792 | Bulk Product a6cf9d4a | Electronics | $298.75 | 364 | ★ 1.0 | 67 | BULK-856efb12 |
| 5793 | Bulk Product 081d0670 | Books | $637.94 | 44 | ★ 1.8 | 11 | BULK-78c457e3 |
| 5794 | Bulk Product 183b17da | Home & Garden | $57.29 | 419 | ★ 3.8 | 45 | BULK-ef34cff6 |
| 5795 | Bulk Product 930397fb | Home & Garden | $877.83 | 417 | ★ 0.8 | 39 | BULK-e8d03126 |
| 5796 | Bulk Product b6cf091d | Clothing | $756.09 | 19 | ★ 4.8 | 78 | BULK-adfc1f59 |
| 5797 | Bulk Product 4eedc846 | Clothing | $570.69 | 83 | ★ 4.9 | 23 | BULK-0a3f376e |
| 5798 | Bulk Product 3e08f2e1 | Electronics | $975.78 | 99 | ★ 3.0 | 4 | BULK-ba0d3f12 |
| 5799 | Bulk Product 75ad9af3 | Electronics | $144.07 | 124 | ★ 2.5 | 30 | BULK-45b1ab55 |
| 5800 | Bulk Product 42e70ade | Clothing | $612.86 | 481 | ★ 4.1 | 34 | BULK-fded972c |
| 5801 | Bulk Product 9a5bec79 | Electronics | $182.76 | 380 | ★ 0.1 | 75 | BULK-8bdae855 |
| 5802 | Bulk Product 5d7347be | Clothing | $399.08 | 125 | ★ 1.6 | 20 | BULK-efee60cc |
| 5803 | Bulk Product ff045f78 | Sports & Outdoors | $514.87 | 234 | ★ 2.9 | 45 | BULK-757abebd |
| 5804 | Bulk Product 72ff7551 | Home & Garden | $11.83 | 143 | ★ 4.3 | 48 | BULK-ea0aaf21 |
| 5805 | Bulk Product f6981625 | Books | $647.21 | 74 | ★ 0.5 | 41 | BULK-fbe3362a |
| 5806 | Bulk Product b0dad746 | Sports & Outdoors | $447.57 | 70 | ★ 3.5 | 53 | BULK-38bba85d |
| 5807 | Bulk Product 465fcbdb | Sports & Outdoors | $767.80 | 92 | ★ 2.5 | 1 | BULK-0220bea0 |
| 5808 | Bulk Product 858e1375 | Toys & Games | $372.57 | 190 | ★ 0.5 | 12 | BULK-08d20e6c |
| 5809 | Bulk Product bf3cf540 | Sports & Outdoors | $658.72 | 286 | ★ 4.7 | 45 | BULK-ac214c72 |
// 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
};
}