Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 15160 | Bulk Product 594bb818 | Toys & Games | $970.12 | 420 | ★ 1.1 | 9 | BULK-e5aa92a4 |
| 15161 | Bulk Product 78cdbf5b | Clothing | $528.91 | 38 | ★ 0.8 | 31 | BULK-44718f80 |
| 15162 | Bulk Product a39d402f | Electronics | $178.96 | 417 | ★ 4.0 | 68 | BULK-c5b7c197 |
| 15163 | Bulk Product ed65c5f0 | Books | $84.57 | 468 | ★ 1.3 | 6 | BULK-752d638a |
| 15164 | Bulk Product b2a437e6 | Electronics | $945.14 | 219 | ★ 3.3 | 71 | BULK-6a630476 |
| 15165 | Bulk Product 1aa42d4e | Toys & Games | $462.17 | 206 | ★ 3.2 | 52 | BULK-359e5632 |
| 15166 | Bulk Product 5f6451e1 | Home & Garden | $267.45 | 311 | ★ 2.5 | 58 | BULK-6027ce20 |
| 15167 | Bulk Product 1c18b70d | Toys & Games | $412.41 | 83 | ★ 4.6 | 0 | BULK-66125dd8 |
| 15168 | Bulk Product f517840b | Electronics | $728.78 | 101 | ★ 0.7 | 20 | BULK-b3dced10 |
| 15169 | Bulk Product f3c14080 | Clothing | $39.24 | 158 | ★ 1.9 | 11 | BULK-5bca717a |
| 15170 | Bulk Product 93e5f0e6 | Clothing | $97.12 | 29 | ★ 2.4 | 94 | BULK-524f0883 |
| 15171 | Bulk Product 48232f94 | Toys & Games | $517.14 | 418 | ★ 3.2 | 93 | BULK-19451ccf |
| 15172 | Bulk Product 36cee84a | Toys & Games | $42.74 | 237 | ★ 3.0 | 46 | BULK-72287b55 |
| 15173 | Bulk Product adf94e3a | Books | $766.85 | 427 | ★ 2.6 | 90 | BULK-9e7985f2 |
| 15174 | Bulk Product 5787c46e | Home & Garden | $442.44 | 377 | ★ 2.9 | 52 | BULK-04a11f95 |
| 15175 | Bulk Product 926163cb | Electronics | $78.85 | 319 | ★ 2.3 | 80 | BULK-f7960967 |
| 15176 | Bulk Product 52bd86c8 | Electronics | $995.74 | 364 | ★ 2.4 | 73 | BULK-64dcc896 |
| 15177 | Bulk Product ba4dbeb9 | Clothing | $946.90 | 496 | ★ 3.3 | 12 | BULK-5f7b0af9 |
| 15178 | Bulk Product 8fcb8054 | Home & Garden | $172.37 | 33 | ★ 2.9 | 57 | BULK-3cbbc1ac |
| 15179 | Bulk Product 956c3406 | Electronics | $964.91 | 109 | ★ 4.3 | 81 | BULK-b1579eb0 |
| 15180 | Bulk Product bd61ad33 | Clothing | $911.23 | 338 | ★ 0.4 | 28 | BULK-2855ddfa |
| 15181 | Bulk Product fed8dc47 | Sports & Outdoors | $288.62 | 278 | ★ 2.8 | 11 | BULK-55b342f4 |
| 15182 | Bulk Product 6293783f | Sports & Outdoors | $886.76 | 347 | ★ 3.2 | 59 | BULK-758abde1 |
| 15183 | Bulk Product d9c4018c | Books | $93.33 | 44 | ★ 2.5 | 24 | BULK-fd82041f |
| 15184 | Bulk Product 5140f825 | Toys & Games | $846.47 | 409 | ★ 2.8 | 86 | BULK-70257014 |
// 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
};
}