Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 9010 | Bulk Product 5c903a22 | Electronics | $492.97 | 86 | ★ 0.8 | 39 | BULK-7f1af46d |
| 9011 | Bulk Product 9b623c2a | Books | $320.42 | 172 | ★ 0.6 | 53 | BULK-55439da1 |
| 9012 | Bulk Product 4c2b9ac8 | Sports & Outdoors | $694.33 | 367 | ★ 2.5 | 23 | BULK-e1683d53 |
| 9013 | Bulk Product 86da08e3 | Sports & Outdoors | $961.45 | 158 | ★ 1.1 | 70 | BULK-92c2670b |
| 9014 | Bulk Product d608ccc1 | Clothing | $758.98 | 360 | ★ 0.7 | 49 | BULK-8051c7b0 |
| 9015 | Bulk Product 51dbbd58 | Books | $574.76 | 373 | ★ 1.7 | 52 | BULK-e1f676d2 |
| 9016 | Bulk Product 0f4e35b2 | Clothing | $572.68 | 270 | ★ 3.9 | 8 | BULK-dcb9833e |
| 9017 | Bulk Product bed243c4 | Electronics | $624.39 | 445 | ★ 0.6 | 20 | BULK-eba9f117 |
| 9018 | Bulk Product 20ab5555 | Clothing | $325.00 | 193 | ★ 1.3 | 87 | BULK-66b53976 |
| 9019 | Bulk Product c2fbbcb7 | Electronics | $932.38 | 143 | ★ 0.6 | 90 | BULK-b7f600c9 |
| 9020 | Bulk Product 7494fe49 | Electronics | $615.43 | 324 | ★ 0.7 | 47 | BULK-9e24b17d |
| 9021 | Bulk Product 642180d6 | Clothing | $1,004.82 | 291 | ★ 3.3 | 45 | BULK-9943309d |
| 9022 | Bulk Product 03f9d4e3 | Toys & Games | $538.75 | 377 | ★ 1.6 | 50 | BULK-64ee3d4e |
| 9023 | Bulk Product 1675d404 | Home & Garden | $692.01 | 164 | ★ 1.6 | 76 | BULK-878633e1 |
| 9024 | Bulk Product 73791d18 | Toys & Games | $578.92 | 344 | ★ 4.8 | 67 | BULK-2aa6c7bd |
| 9025 | Bulk Product 75404ee2 | Clothing | $949.74 | 407 | ★ 4.0 | 35 | BULK-4d4a6b13 |
| 9026 | Bulk Product 42e875b6 | Toys & Games | $55.25 | 425 | ★ 4.6 | 4 | BULK-81eea77b |
| 9027 | Bulk Product 0e797604 | Home & Garden | $648.69 | 432 | ★ 2.4 | 81 | BULK-3a52e887 |
| 9028 | Bulk Product f7415cbd | Sports & Outdoors | $959.37 | 22 | ★ 4.3 | 77 | BULK-07ee33df |
| 9029 | Bulk Product 4ca21f15 | Books | $948.10 | 190 | ★ 4.3 | 24 | BULK-90ff20d7 |
| 9030 | Bulk Product 5e77bae1 | Home & Garden | $458.81 | 261 | ★ 1.4 | 87 | BULK-122173e0 |
| 9031 | Bulk Product 699d8edd | Sports & Outdoors | $634.73 | 137 | ★ 1.5 | 74 | BULK-77e99d9e |
| 9032 | Bulk Product bc2f2e34 | Electronics | $850.66 | 78 | ★ 0.3 | 33 | BULK-5df53b69 |
| 9033 | Bulk Product 2d0c40db | Home & Garden | $663.91 | 218 | ★ 0.5 | 33 | BULK-6f265e75 |
| 9034 | Bulk Product 554ef9e3 | Clothing | $592.03 | 8 | ★ 3.7 | 68 | BULK-d5fa57bd |
// 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
};
}