Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 14210 | Bulk Product e979eec9 | Electronics | $950.02 | 328 | ★ 1.6 | 15 | BULK-edcfa7ca |
| 14211 | Bulk Product 68ca7c34 | Sports & Outdoors | $257.90 | 165 | ★ 2.4 | 29 | BULK-4616072d |
| 14212 | Bulk Product d6a16143 | Books | $109.10 | 489 | ★ 0.8 | 45 | BULK-d45ad925 |
| 14213 | Bulk Product 2af96c74 | Toys & Games | $277.62 | 464 | ★ 3.3 | 93 | BULK-f4aeb64f |
| 14214 | Bulk Product 5affb1e5 | Sports & Outdoors | $172.40 | 177 | ★ 3.9 | 1 | BULK-15b53a6d |
| 14215 | Bulk Product 802bd257 | Sports & Outdoors | $580.06 | 390 | ★ 4.8 | 88 | BULK-ea2b6ae7 |
| 14216 | Bulk Product 771bbd00 | Sports & Outdoors | $64.12 | 390 | ★ 1.2 | 45 | BULK-8601dbd0 |
| 14217 | Bulk Product d7de4b31 | Books | $296.15 | 3 | ★ 1.0 | 0 | BULK-365bf5aa |
| 14218 | Bulk Product 26e915c5 | Sports & Outdoors | $979.83 | 220 | ★ 1.9 | 37 | BULK-cb7bec29 |
| 14219 | Bulk Product 99a30912 | Home & Garden | $476.75 | 132 | ★ 3.3 | 46 | BULK-3496db06 |
| 14220 | Bulk Product 01797e64 | Electronics | $870.06 | 486 | ★ 1.3 | 73 | BULK-d17fa504 |
| 14221 | Bulk Product 44d57b67 | Electronics | $569.12 | 33 | ★ 3.1 | 40 | BULK-d365cc6a |
| 14222 | Bulk Product 2837c2a2 | Sports & Outdoors | $852.59 | 64 | ★ 2.8 | 54 | BULK-cb9070ef |
| 14223 | Bulk Product 630ffef7 | Home & Garden | $700.22 | 363 | ★ 0.6 | 14 | BULK-c395def3 |
| 14224 | Bulk Product 182c1bf7 | Books | $387.03 | 120 | ★ 4.0 | 49 | BULK-80014cf7 |
| 14225 | Bulk Product 6c9de133 | Home & Garden | $280.94 | 70 | ★ 4.1 | 26 | BULK-58887c71 |
| 14226 | Bulk Product b51016fe | Electronics | $858.03 | 258 | ★ 2.0 | 91 | BULK-22f103d7 |
| 14227 | Bulk Product 966e956d | Electronics | $346.91 | 171 | ★ 2.5 | 28 | BULK-6a3bdf2c |
| 14228 | Bulk Product 3bdf4b34 | Sports & Outdoors | $449.90 | 429 | ★ 3.7 | 87 | BULK-8f6bb2cc |
| 14229 | Bulk Product 039066af | Toys & Games | $135.99 | 240 | ★ 0.0 | 0 | BULK-fc3fe298 |
| 14230 | Bulk Product be4b1e63 | Clothing | $732.58 | 161 | ★ 3.9 | 48 | BULK-0439d532 |
| 14231 | Bulk Product 3c050d06 | Sports & Outdoors | $871.11 | 260 | ★ 1.5 | 12 | BULK-148fdd01 |
| 14232 | Bulk Product 53834e84 | Sports & Outdoors | $844.82 | 237 | ★ 3.9 | 34 | BULK-2336a3b1 |
| 14233 | Bulk Product c37af381 | Electronics | $706.47 | 150 | ★ 0.9 | 87 | BULK-e6c7ffed |
| 14234 | Bulk Product 8d017d27 | Clothing | $23.49 | 457 | ★ 4.8 | 76 | BULK-3445a2a8 |
// 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
};
}