Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 9210 | Bulk Product 81085ddb | Electronics | $1,001.01 | 39 | ★ 1.2 | 69 | BULK-1d8512b1 |
| 9211 | Bulk Product 0b3f4b26 | Electronics | $874.08 | 176 | ★ 4.1 | 54 | BULK-0edc9068 |
| 9212 | Bulk Product d3f6e3ad | Home & Garden | $718.37 | 425 | ★ 1.4 | 77 | BULK-767b006f |
| 9213 | Bulk Product 904f68e1 | Home & Garden | $459.99 | 165 | ★ 3.7 | 47 | BULK-788b9037 |
| 9214 | Bulk Product 9b19ab6b | Electronics | $616.09 | 464 | ★ 1.1 | 55 | BULK-c57922e1 |
| 9215 | Bulk Product b3eddbb8 | Electronics | $878.77 | 138 | ★ 4.3 | 29 | BULK-40b1d755 |
| 9216 | Bulk Product 00c54dca | Home & Garden | $625.47 | 204 | ★ 0.7 | 7 | BULK-1edda033 |
| 9217 | Bulk Product 67a876c1 | Books | $870.08 | 233 | ★ 1.0 | 90 | BULK-16cf2540 |
| 9218 | Bulk Product 9cea297a | Home & Garden | $184.78 | 430 | ★ 1.4 | 59 | BULK-3b6ae8e0 |
| 9219 | Bulk Product c4bcfc1e | Toys & Games | $280.81 | 434 | ★ 1.0 | 59 | BULK-aa03e8f9 |
| 9220 | Bulk Product ddb66445 | Books | $565.92 | 279 | ★ 1.7 | 37 | BULK-5872e839 |
| 9221 | Bulk Product 7bdceb79 | Home & Garden | $803.39 | 51 | ★ 2.3 | 0 | BULK-0fc9fa0f |
| 9222 | Bulk Product 7b148866 | Electronics | $443.11 | 44 | ★ 3.9 | 90 | BULK-e05306a7 |
| 9223 | Bulk Product 6637160f | Toys & Games | $157.82 | 475 | ★ 1.4 | 97 | BULK-71db5680 |
| 9224 | Bulk Product d2a9e65d | Clothing | $316.24 | 146 | ★ 2.9 | 56 | BULK-87c3a6f0 |
| 9225 | Bulk Product d1fe5060 | Books | $455.17 | 383 | ★ 3.5 | 22 | BULK-d225e6d2 |
| 9226 | Bulk Product 623594cb | Books | $751.47 | 314 | ★ 3.5 | 64 | BULK-e96abe54 |
| 9227 | Bulk Product 55e6e6eb | Clothing | $692.44 | 378 | ★ 3.6 | 70 | BULK-be0677be |
| 9228 | Bulk Product 6a7055ae | Home & Garden | $358.67 | 250 | ★ 2.4 | 93 | BULK-f348aaf5 |
| 9229 | Bulk Product 5d30544a | Toys & Games | $90.47 | 432 | ★ 1.3 | 60 | BULK-a99e964e |
| 9230 | Bulk Product cc9644ac | Electronics | $147.04 | 216 | ★ 4.0 | 76 | BULK-9ae00233 |
| 9231 | Bulk Product 9b1a6256 | Sports & Outdoors | $685.98 | 293 | ★ 2.2 | 41 | BULK-57010c0f |
| 9232 | Bulk Product 688d28e5 | Books | $163.86 | 344 | ★ 4.7 | 61 | BULK-1149ae6f |
| 9233 | Bulk Product 4557c73f | Clothing | $785.26 | 389 | ★ 2.9 | 40 | BULK-3277898d |
| 9234 | Bulk Product 01ec079f | Home & Garden | $142.76 | 177 | ★ 0.0 | 46 | BULK-8e2c1f0a |
// 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
};
}