Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 16135 | Bulk Product c87614f0 | Home & Garden | $58.21 | 413 | ★ 3.6 | 75 | BULK-9fddf0fd |
| 16136 | Bulk Product a552464f | Home & Garden | $250.71 | 466 | ★ 2.6 | 15 | BULK-3dfb683f |
| 16137 | Bulk Product e102de3d | Toys & Games | $765.27 | 482 | ★ 1.1 | 25 | BULK-86156231 |
| 16138 | Bulk Product 20767e9b | Books | $308.08 | 214 | ★ 4.8 | 51 | BULK-32055d32 |
| 16139 | Bulk Product 547f2aaf | Books | $218.89 | 364 | ★ 4.1 | 37 | BULK-118c5040 |
| 16140 | Bulk Product 121d9b67 | Sports & Outdoors | $232.46 | 177 | ★ 2.9 | 23 | BULK-3edbac39 |
| 16141 | Bulk Product bff7d8fd | Books | $696.28 | 355 | ★ 1.5 | 72 | BULK-1e38a4fb |
| 16142 | Bulk Product 0a50cba7 | Toys & Games | $79.73 | 152 | ★ 3.1 | 37 | BULK-07f08821 |
| 16143 | Bulk Product d69cd1a6 | Electronics | $901.33 | 396 | ★ 4.2 | 33 | BULK-69444b9b |
| 16144 | Bulk Product 3c891519 | Home & Garden | $512.31 | 343 | ★ 1.8 | 45 | BULK-d284555e |
| 16145 | Bulk Product bcdbe4e5 | Sports & Outdoors | $426.58 | 302 | ★ 3.0 | 22 | BULK-e72d9b20 |
| 16146 | Bulk Product 16e07820 | Electronics | $149.72 | 472 | ★ 2.4 | 42 | BULK-1bceb3ea |
| 16147 | Bulk Product c648ff76 | Home & Garden | $821.47 | 251 | ★ 1.7 | 19 | BULK-bc340d3a |
| 16148 | Bulk Product 7cecbaf9 | Electronics | $763.50 | 338 | ★ 1.6 | 82 | BULK-3ee8ec16 |
| 16149 | Bulk Product cc75a76d | Home & Garden | $851.71 | 271 | ★ 0.5 | 59 | BULK-ca59c63d |
| 16150 | Bulk Product 631c169e | Books | $137.76 | 336 | ★ 0.8 | 63 | BULK-72c3d195 |
| 16151 | Bulk Product 19c20279 | Electronics | $648.28 | 496 | ★ 1.2 | 44 | BULK-0ef52f06 |
| 16152 | Bulk Product 460dfb1f | Books | $31.30 | 344 | ★ 2.7 | 84 | BULK-3aa0720b |
| 16153 | Bulk Product 24fc60fa | Electronics | $923.11 | 266 | ★ 1.5 | 68 | BULK-f55c21d4 |
| 16154 | Bulk Product 9368733e | Clothing | $931.45 | 354 | ★ 1.4 | 67 | BULK-5f779ecb |
| 16155 | Bulk Product 6e6db517 | Clothing | $1,004.22 | 266 | ★ 1.8 | 15 | BULK-092f5c00 |
| 16156 | Bulk Product 1befbd94 | Electronics | $614.98 | 156 | ★ 2.0 | 54 | BULK-67a8ced1 |
| 16157 | Bulk Product 72edba7a | Toys & Games | $606.98 | 3 | ★ 2.9 | 64 | BULK-9889532f |
| 16158 | Bulk Product 52b15c6f | Electronics | $342.45 | 481 | ★ 3.1 | 19 | BULK-e802d6a4 |
| 16159 | Bulk Product 6f3e8cf3 | Sports & Outdoors | $585.26 | 198 | ★ 2.9 | 70 | BULK-3acadcec |
// 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
};
}