Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 6410 | Bulk Product 79251fbd | Home & Garden | $231.84 | 38 | ★ 3.2 | 13 | BULK-ae98d106 |
| 6411 | Bulk Product fb3980da | Books | $852.39 | 203 | ★ 4.5 | 54 | BULK-0a9a0939 |
| 6412 | Bulk Product 1c4b0bf1 | Sports & Outdoors | $252.37 | 496 | ★ 1.5 | 16 | BULK-1751a524 |
| 6413 | Bulk Product bacb1349 | Clothing | $656.03 | 32 | ★ 4.1 | 19 | BULK-7ec7626b |
| 6414 | Bulk Product e7175642 | Toys & Games | $636.62 | 456 | ★ 2.5 | 46 | BULK-4b653b50 |
| 6415 | Bulk Product e5b47ab1 | Books | $235.59 | 439 | ★ 1.1 | 69 | BULK-698abb7b |
| 6416 | Bulk Product bc5bf6ac | Books | $146.81 | 443 | ★ 3.0 | 9 | BULK-8fbfed65 |
| 6417 | Bulk Product baf0a6b6 | Books | $718.52 | 234 | ★ 3.7 | 98 | BULK-73bc95cb |
| 6418 | Bulk Product b4426165 | Sports & Outdoors | $55.88 | 11 | ★ 3.2 | 13 | BULK-523ab4c7 |
| 6419 | Bulk Product 09e3e370 | Electronics | $852.34 | 451 | ★ 4.7 | 16 | BULK-548fefab |
| 6420 | Bulk Product bc6480d7 | Clothing | $530.02 | 270 | ★ 2.2 | 71 | BULK-bf987565 |
| 6421 | Bulk Product 5452bb56 | Home & Garden | $291.54 | 276 | ★ 3.3 | 90 | BULK-b786d164 |
| 6422 | Bulk Product 05316b8a | Toys & Games | $552.76 | 173 | ★ 3.6 | 58 | BULK-9a5326c7 |
| 6423 | Bulk Product 421e857a | Home & Garden | $422.75 | 305 | ★ 4.4 | 27 | BULK-4402ebb8 |
| 6424 | Bulk Product 7a01b10f | Sports & Outdoors | $292.77 | 303 | ★ 1.3 | 26 | BULK-6bc51b49 |
| 6425 | Bulk Product 1e2cc839 | Home & Garden | $778.41 | 343 | ★ 0.7 | 66 | BULK-105cb362 |
| 6426 | Bulk Product eae7a3fb | Electronics | $443.98 | 455 | ★ 0.7 | 13 | BULK-d61e1889 |
| 6427 | Bulk Product 3cbd8cb6 | Electronics | $702.17 | 448 | ★ 3.3 | 95 | BULK-93b7854a |
| 6428 | Bulk Product 20484335 | Toys & Games | $597.44 | 50 | ★ 1.7 | 65 | BULK-5bbac261 |
| 6429 | Bulk Product cc4b3a2f | Electronics | $805.36 | 360 | ★ 0.1 | 67 | BULK-3b8bfa7e |
| 6430 | Bulk Product 085b0933 | Electronics | $513.50 | 446 | ★ 2.5 | 77 | BULK-e5983e69 |
| 6431 | Bulk Product d8cb70fb | Books | $162.73 | 118 | ★ 4.9 | 10 | BULK-f2796b51 |
| 6432 | Bulk Product 1726c4c8 | Toys & Games | $613.87 | 259 | ★ 3.8 | 43 | BULK-45f919d3 |
| 6433 | Bulk Product 7694edf2 | Electronics | $811.44 | 447 | ★ 1.3 | 34 | BULK-3cff327c |
| 6434 | Bulk Product 6d14c174 | Electronics | $409.32 | 363 | ★ 2.6 | 36 | BULK-6af3c638 |
| 6435 | Bulk Product 3cdf7cbb | Sports & Outdoors | $975.51 | 180 | ★ 1.4 | 43 | BULK-7923f12e |
| 6436 | Bulk Product a6743347 | Clothing | $629.14 | 89 | ★ 2.0 | 58 | BULK-0aca4198 |
| 6437 | Bulk Product 787bb1b3 | Books | $32.32 | 147 | ★ 2.9 | 2 | BULK-62581c0a |
| 6438 | Bulk Product 1fae8c8b | Toys & Games | $969.19 | 156 | ★ 2.6 | 39 | BULK-dbfd4812 |
| 6439 | Bulk Product fa7559b2 | Toys & Games | $530.52 | 166 | ★ 4.0 | 13 | BULK-58cb8c13 |
| 6440 | Bulk Product 66472cb6 | Sports & Outdoors | $792.74 | 354 | ★ 3.4 | 41 | BULK-d906a1c7 |
| 6441 | Bulk Product 86db19ee | Electronics | $104.24 | 200 | ★ 4.9 | 81 | BULK-7787d2a5 |
| 6442 | Bulk Product 68bd4bd8 | Sports & Outdoors | $129.78 | 269 | ★ 4.2 | 19 | BULK-c019956a |
| 6443 | Bulk Product af484f0f | Sports & Outdoors | $434.36 | 30 | ★ 3.9 | 30 | BULK-f1a25201 |
| 6444 | Bulk Product 93759770 | Clothing | $567.51 | 182 | ★ 1.6 | 51 | BULK-4e927ce9 |
| 6445 | Bulk Product 70524502 | Books | $728.28 | 148 | ★ 0.2 | 94 | BULK-16f21feb |
| 6446 | Bulk Product 95cc4572 | Sports & Outdoors | $167.54 | 463 | ★ 2.0 | 75 | BULK-5170b839 |
| 6447 | Bulk Product 8dd3b177 | Clothing | $964.16 | 193 | ★ 0.4 | 60 | BULK-1b565d91 |
| 6448 | Bulk Product c0927625 | Books | $761.24 | 399 | ★ 1.1 | 85 | BULK-65f7fef3 |
| 6449 | Bulk Product e8278210 | Books | $363.08 | 101 | ★ 3.3 | 70 | BULK-8114d5cd |
| 6450 | Bulk Product 8a8bf09e | Clothing | $962.22 | 370 | ★ 0.2 | 43 | BULK-e5b6ba79 |
| 6451 | Bulk Product 411e31d0 | Home & Garden | $222.83 | 270 | ★ 3.0 | 80 | BULK-131a97c3 |
| 6452 | Bulk Product 54f1ac36 | Clothing | $421.64 | 135 | ★ 4.6 | 70 | BULK-ac0e9e2c |
| 6453 | Bulk Product 2a21ff4e | Sports & Outdoors | $745.10 | 188 | ★ 2.7 | 10 | BULK-6d0bc837 |
| 6454 | Bulk Product 0ff7654d | Sports & Outdoors | $307.55 | 96 | ★ 2.1 | 62 | BULK-777f5959 |
| 6455 | Bulk Product ab7101d5 | Electronics | $424.67 | 102 | ★ 0.2 | 30 | BULK-e6a4bf5b |
| 6456 | Bulk Product eaef11ab | Sports & Outdoors | $468.15 | 356 | ★ 3.1 | 77 | BULK-545144cd |
| 6457 | Bulk Product 528a3253 | Clothing | $362.69 | 410 | ★ 0.5 | 84 | BULK-26e94f95 |
| 6458 | Bulk Product 13f09407 | Clothing | $362.97 | 358 | ★ 1.7 | 67 | BULK-38ee9ad0 |
| 6459 | Bulk Product 93cb0c8a | Sports & Outdoors | $231.87 | 303 | ★ 2.5 | 65 | BULK-f1654eaf |
// 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
};
}