Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 24860 | Bulk Product e7c311e8 | Sports & Outdoors | $203.76 | 298 | ★ 2.0 | 94 | BULK-fe9be77e |
| 24861 | Bulk Product 6eeb2208 | Toys & Games | $289.83 | 215 | ★ 3.3 | 91 | BULK-e26a72f0 |
| 24862 | Bulk Product d4ccb5fa | Toys & Games | $638.29 | 221 | ★ 1.7 | 69 | BULK-cc378b8c |
| 24863 | Bulk Product 1e0bd201 | Sports & Outdoors | $852.53 | 252 | ★ 1.8 | 83 | BULK-a1b99b48 |
| 24864 | Bulk Product 01ae3b1b | Books | $973.33 | 70 | ★ 3.2 | 43 | BULK-c329aeea |
| 24865 | Bulk Product a1a786c1 | Electronics | $706.08 | 394 | ★ 4.5 | 91 | BULK-be13de9d |
| 24866 | Bulk Product 3413da91 | Home & Garden | $629.80 | 367 | ★ 3.8 | 3 | BULK-ee139a43 |
| 24867 | Bulk Product 9870ae8c | Books | $430.85 | 481 | ★ 3.5 | 69 | BULK-dc9273b4 |
| 24868 | Bulk Product b19ec2d3 | Toys & Games | $446.29 | 53 | ★ 3.7 | 69 | BULK-281648ab |
| 24869 | Bulk Product 7172e0b2 | Clothing | $541.74 | 59 | ★ 2.3 | 71 | BULK-8e1e224e |
| 24870 | Bulk Product 0f646ab7 | Books | $606.73 | 288 | ★ 1.1 | 63 | BULK-8b88dc0f |
| 24871 | Bulk Product 2fb392e8 | Electronics | $475.65 | 296 | ★ 2.6 | 8 | BULK-993930c3 |
| 24872 | Bulk Product 9931e89f | Home & Garden | $14.32 | 297 | ★ 2.8 | 18 | BULK-c0264698 |
| 24873 | Bulk Product 460d2172 | Books | $977.49 | 122 | ★ 3.2 | 67 | BULK-7cfb6c56 |
| 24874 | Bulk Product 1901be08 | Books | $400.26 | 96 | ★ 1.7 | 29 | BULK-69045eb9 |
| 24875 | Bulk Product 38fb222e | Sports & Outdoors | $70.46 | 15 | ★ 3.4 | 9 | BULK-e5bec0bd |
| 24876 | Bulk Product 89f793ac | Electronics | $568.93 | 366 | ★ 4.4 | 63 | BULK-02a7651a |
| 24877 | Bulk Product c0fe3379 | Toys & Games | $296.75 | 3 | ★ 3.2 | 66 | BULK-d105f6b7 |
| 24878 | Bulk Product e072c858 | Toys & Games | $698.13 | 268 | ★ 4.6 | 38 | BULK-e79c7c10 |
| 24879 | Bulk Product 43235dab | Clothing | $117.87 | 146 | ★ 0.9 | 85 | BULK-d237a3af |
| 24880 | Bulk Product 93f0c263 | Sports & Outdoors | $976.71 | 154 | ★ 2.9 | 94 | BULK-412e5359 |
| 24881 | Bulk Product 730c95cb | Clothing | $614.11 | 353 | ★ 4.8 | 94 | BULK-7c36b630 |
| 24882 | Bulk Product c9b357f5 | Electronics | $427.59 | 298 | ★ 1.7 | 15 | BULK-a500b8a7 |
| 24883 | Bulk Product 1e019fd1 | Toys & Games | $783.60 | 312 | ★ 2.6 | 80 | BULK-10ade88e |
| 24884 | Bulk Product e80a3314 | Electronics | $982.53 | 397 | ★ 2.3 | 15 | BULK-03c791bb |
// 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
};
}