Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 9635 | Bulk Product f723b816 | Electronics | $604.74 | 166 | ★ 3.7 | 6 | BULK-4d914bb0 |
| 9636 | Bulk Product df3cd1c9 | Toys & Games | $663.51 | 217 | ★ 3.0 | 40 | BULK-ac8758d6 |
| 9637 | Bulk Product 6ff35be1 | Sports & Outdoors | $448.29 | 114 | ★ 2.9 | 87 | BULK-e7a5e72c |
| 9638 | Bulk Product f958bf03 | Home & Garden | $572.76 | 193 | ★ 3.3 | 78 | BULK-e2249504 |
| 9639 | Bulk Product fb02aeca | Home & Garden | $13.52 | 157 | ★ 3.6 | 4 | BULK-d98ae58e |
| 9640 | Bulk Product eb9e2f4f | Clothing | $975.60 | 141 | ★ 0.1 | 22 | BULK-b4c5399c |
| 9641 | Bulk Product cc3abba3 | Clothing | $295.52 | 453 | ★ 1.7 | 62 | BULK-967d4490 |
| 9642 | Bulk Product 535df03f | Books | $863.69 | 104 | ★ 1.9 | 24 | BULK-285da128 |
| 9643 | Bulk Product 60c6f403 | Clothing | $406.87 | 147 | ★ 3.4 | 56 | BULK-3064312d |
| 9644 | Bulk Product 1a5e104d | Toys & Games | $487.23 | 222 | ★ 2.0 | 54 | BULK-8550d8b9 |
| 9645 | Bulk Product 37e4c568 | Electronics | $443.08 | 317 | ★ 3.6 | 30 | BULK-c60704e3 |
| 9646 | Bulk Product 4d035859 | Books | $462.78 | 338 | ★ 1.5 | 99 | BULK-ac3e9c1a |
| 9647 | Bulk Product 790f2ae2 | Electronics | $587.81 | 176 | ★ 0.4 | 86 | BULK-fb3c52b5 |
| 9648 | Bulk Product 645510cf | Electronics | $578.88 | 214 | ★ 3.3 | 48 | BULK-fe8a6859 |
| 9649 | Bulk Product 60bad7ae | Clothing | $920.34 | 316 | ★ 0.4 | 17 | BULK-52ee1fa5 |
| 9650 | Bulk Product 6a860862 | Home & Garden | $860.15 | 243 | ★ 4.5 | 26 | BULK-cdb18d52 |
| 9651 | Bulk Product 01fa7391 | Electronics | $163.17 | 219 | ★ 4.1 | 49 | BULK-e0625b44 |
| 9652 | Bulk Product 48c20872 | Sports & Outdoors | $633.22 | 416 | ★ 3.1 | 20 | BULK-0325a3b9 |
| 9653 | Bulk Product 4664083a | Sports & Outdoors | $490.50 | 350 | ★ 0.1 | 0 | BULK-1bad6f15 |
| 9654 | Bulk Product ce1c1d87 | Books | $538.87 | 68 | ★ 0.8 | 25 | BULK-34014b5c |
| 9655 | Bulk Product 053ed91b | Electronics | $209.65 | 276 | ★ 3.8 | 61 | BULK-d3463860 |
| 9656 | Bulk Product cc990ea4 | Books | $468.86 | 442 | ★ 3.9 | 1 | BULK-65232914 |
| 9657 | Bulk Product 6bd7590d | Books | $492.07 | 344 | ★ 4.2 | 1 | BULK-cb61936b |
| 9658 | Bulk Product be48c1c6 | Home & Garden | $894.73 | 136 | ★ 1.3 | 5 | BULK-a4288a7d |
| 9659 | Bulk Product f91c4790 | Electronics | $245.11 | 451 | ★ 2.7 | 63 | BULK-e26773c7 |
// 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
};
}