Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 5935 | Bulk Product b3208811 | Electronics | $230.42 | 435 | ★ 1.3 | 19 | BULK-9a45f240 |
| 5936 | Bulk Product f7c90f89 | Clothing | $753.43 | 235 | ★ 4.3 | 78 | BULK-014f2db1 |
| 5937 | Bulk Product 40e4c5bd | Clothing | $356.79 | 279 | ★ 4.8 | 4 | BULK-1553ab5d |
| 5938 | Bulk Product f5e0855c | Home & Garden | $336.97 | 226 | ★ 4.5 | 11 | BULK-dc48177b |
| 5939 | Bulk Product beab5e03 | Home & Garden | $87.66 | 414 | ★ 0.9 | 93 | BULK-343e2e2a |
| 5940 | Bulk Product ccb1fd83 | Electronics | $862.84 | 107 | ★ 1.6 | 62 | BULK-e6a1b9a3 |
| 5941 | Bulk Product bf2d1c8e | Clothing | $60.81 | 215 | ★ 1.3 | 56 | BULK-f6f80343 |
| 5942 | Bulk Product 3b75fdbb | Electronics | $823.81 | 451 | ★ 3.7 | 48 | BULK-18ed0b25 |
| 5943 | Bulk Product 9268babd | Books | $701.15 | 121 | ★ 0.1 | 49 | BULK-03929842 |
| 5944 | Bulk Product 3125f069 | Electronics | $947.82 | 379 | ★ 4.8 | 19 | BULK-cd5c2fc3 |
| 5945 | Bulk Product bf5609e3 | Electronics | $197.71 | 464 | ★ 0.1 | 80 | BULK-3858f882 |
| 5946 | Bulk Product 522cdb3e | Toys & Games | $855.46 | 386 | ★ 2.4 | 92 | BULK-8498edea |
| 5947 | Bulk Product 8e9a454e | Books | $320.03 | 60 | ★ 2.2 | 32 | BULK-d298a126 |
| 5948 | Bulk Product c0f3204c | Electronics | $46.92 | 284 | ★ 3.3 | 74 | BULK-2244195e |
| 5949 | Bulk Product bc68aa52 | Sports & Outdoors | $580.29 | 308 | ★ 2.7 | 93 | BULK-7d25adaf |
| 5950 | Bulk Product 2ef36b6c | Home & Garden | $130.84 | 349 | ★ 0.0 | 98 | BULK-56b06d9c |
| 5951 | Bulk Product bfc9fb3a | Sports & Outdoors | $858.15 | 171 | ★ 2.7 | 67 | BULK-80d06729 |
| 5952 | Bulk Product 1061e781 | Toys & Games | $400.94 | 440 | ★ 1.9 | 99 | BULK-6124fb8a |
| 5953 | Bulk Product f7df3407 | Electronics | $672.66 | 116 | ★ 3.6 | 26 | BULK-f461536a |
| 5954 | Bulk Product 5e531e33 | Clothing | $437.91 | 201 | ★ 2.6 | 67 | BULK-02f44feb |
| 5955 | Bulk Product 75c54888 | Home & Garden | $349.82 | 433 | ★ 1.9 | 28 | BULK-bfbc7d4b |
| 5956 | Bulk Product 83f9c7c7 | Electronics | $202.06 | 346 | ★ 4.4 | 38 | BULK-c6bd87ef |
| 5957 | Bulk Product f384f08b | Toys & Games | $10.45 | 179 | ★ 1.4 | 96 | BULK-6d7b1488 |
| 5958 | Bulk Product a62fa1d5 | Home & Garden | $259.16 | 287 | ★ 3.7 | 8 | BULK-8be7c893 |
| 5959 | Bulk Product 9941f245 | Toys & Games | $47.56 | 65 | ★ 3.3 | 27 | BULK-75a0a7f1 |
// 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
};
}