Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 18910 | Bulk Product b8cb271c | Clothing | $643.30 | 470 | ★ 1.0 | 58 | BULK-7fb3799f |
| 18911 | Bulk Product 1bf49534 | Clothing | $572.48 | 407 | ★ 1.4 | 97 | BULK-aa29119f |
| 18912 | Bulk Product f3637437 | Electronics | $858.75 | 398 | ★ 1.6 | 71 | BULK-93471691 |
| 18913 | Bulk Product 4708bf27 | Books | $113.75 | 104 | ★ 2.2 | 34 | BULK-fef27990 |
| 18914 | Bulk Product 067abd82 | Books | $617.38 | 64 | ★ 4.8 | 35 | BULK-ee143b87 |
| 18915 | Bulk Product ed777da6 | Toys & Games | $453.14 | 318 | ★ 2.5 | 52 | BULK-ea095515 |
| 18916 | Bulk Product c504e0ff | Electronics | $344.95 | 3 | ★ 0.7 | 4 | BULK-95ab5794 |
| 18917 | Bulk Product 8e498695 | Electronics | $837.32 | 361 | ★ 4.4 | 45 | BULK-cc3bfda0 |
| 18918 | Bulk Product 6d9f7bf8 | Toys & Games | $459.79 | 234 | ★ 1.6 | 38 | BULK-e91df946 |
| 18919 | Bulk Product f018ff88 | Home & Garden | $280.31 | 323 | ★ 2.7 | 86 | BULK-7194047b |
| 18920 | Bulk Product d5d0937d | Electronics | $238.89 | 348 | ★ 2.0 | 35 | BULK-c8184c78 |
| 18921 | Bulk Product 645c606a | Clothing | $540.41 | 26 | ★ 0.6 | 43 | BULK-31c88759 |
| 18922 | Bulk Product 780df223 | Books | $315.31 | 269 | ★ 0.4 | 44 | BULK-2ff13a5e |
| 18923 | Bulk Product 02d818b8 | Sports & Outdoors | $874.83 | 438 | ★ 4.6 | 77 | BULK-5f78d7d6 |
| 18924 | Bulk Product d77a4d48 | Home & Garden | $463.27 | 61 | ★ 3.3 | 21 | BULK-3b884c39 |
| 18925 | Bulk Product 1af58afe | Books | $280.49 | 136 | ★ 0.3 | 80 | BULK-e6ccfb11 |
| 18926 | Bulk Product b3d4c8fa | Electronics | $927.24 | 7 | ★ 1.3 | 76 | BULK-d6caa71e |
| 18927 | Bulk Product 91342a4e | Toys & Games | $191.83 | 233 | ★ 2.9 | 28 | BULK-ceef9846 |
| 18928 | Bulk Product a8f304d3 | Books | $313.12 | 478 | ★ 2.2 | 16 | BULK-df9c5f0f |
| 18929 | Bulk Product ab19de8a | Books | $606.17 | 3 | ★ 0.2 | 98 | BULK-25fe1283 |
| 18930 | Bulk Product d7b080ee | Sports & Outdoors | $320.45 | 265 | ★ 2.2 | 20 | BULK-ff284dbb |
| 18931 | Bulk Product badfb0a1 | Toys & Games | $184.25 | 52 | ★ 2.4 | 60 | BULK-f775925b |
| 18932 | Bulk Product 2d0070ec | Sports & Outdoors | $41.21 | 233 | ★ 4.0 | 18 | BULK-c312d914 |
| 18933 | Bulk Product 0759a6d0 | Clothing | $320.41 | 326 | ★ 4.1 | 75 | BULK-53c84f2d |
| 18934 | Bulk Product 22bd012f | Electronics | $957.82 | 353 | ★ 4.5 | 24 | BULK-0b9f4bd3 |
// 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
};
}