Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 6085 | Bulk Product bc1a365b | Clothing | $56.64 | 118 | ★ 1.3 | 1 | BULK-4dc29072 |
| 6086 | Bulk Product 4c50428a | Toys & Games | $465.53 | 461 | ★ 4.6 | 35 | BULK-98b78d49 |
| 6087 | Bulk Product 016272dd | Clothing | $171.48 | 304 | ★ 1.9 | 46 | BULK-592220c7 |
| 6088 | Bulk Product 87da7768 | Clothing | $84.24 | 331 | ★ 0.6 | 58 | BULK-3f005492 |
| 6089 | Bulk Product 89c5df78 | Home & Garden | $493.10 | 131 | ★ 4.4 | 36 | BULK-7718a1ec |
| 6090 | Bulk Product 0c2d6a25 | Clothing | $835.28 | 333 | ★ 0.5 | 92 | BULK-4abffd16 |
| 6091 | Bulk Product b0e43cbe | Clothing | $388.68 | 319 | ★ 3.8 | 80 | BULK-ba547faf |
| 6092 | Bulk Product 95b8169e | Books | $144.07 | 490 | ★ 1.7 | 36 | BULK-e30051e3 |
| 6093 | Bulk Product 8f121efa | Books | $586.82 | 145 | ★ 3.4 | 52 | BULK-963789e7 |
| 6094 | Bulk Product e5aafaff | Home & Garden | $130.51 | 154 | ★ 5.0 | 39 | BULK-66e8106e |
| 6095 | Bulk Product 86271921 | Clothing | $628.01 | 297 | ★ 2.1 | 76 | BULK-d38f5c32 |
| 6096 | Bulk Product 2fef5686 | Clothing | $66.22 | 19 | ★ 1.5 | 63 | BULK-8bbed0a3 |
| 6097 | Bulk Product 6b607ba7 | Toys & Games | $749.49 | 342 | ★ 2.3 | 91 | BULK-3532523f |
| 6098 | Bulk Product 4133597b | Home & Garden | $503.82 | 16 | ★ 1.7 | 19 | BULK-e51a57ec |
| 6099 | Bulk Product 0e126b66 | Home & Garden | $534.35 | 70 | ★ 1.3 | 39 | BULK-8d821008 |
| 6100 | Bulk Product 439805f8 | Sports & Outdoors | $269.22 | 130 | ★ 3.1 | 77 | BULK-04df6cf0 |
| 6101 | Bulk Product 6f4e18f7 | Home & Garden | $683.70 | 294 | ★ 0.5 | 87 | BULK-bafc70b4 |
| 6102 | Bulk Product 28b9f996 | Home & Garden | $472.31 | 0 | ★ 2.7 | 31 | BULK-79c2b030 |
| 6103 | Bulk Product 80124146 | Clothing | $501.94 | 258 | ★ 3.4 | 85 | BULK-9cfb2572 |
| 6104 | Bulk Product 0acecb0b | Toys & Games | $280.00 | 102 | ★ 2.0 | 7 | BULK-7ccff77f |
| 6105 | Bulk Product 3e4e1415 | Clothing | $449.68 | 187 | ★ 3.3 | 65 | BULK-d7a68ad3 |
| 6106 | Bulk Product bf4daaa8 | Sports & Outdoors | $583.09 | 381 | ★ 4.4 | 63 | BULK-96222327 |
| 6107 | Bulk Product 65b3d7e3 | Toys & Games | $703.75 | 283 | ★ 2.7 | 68 | BULK-9a8e8600 |
| 6108 | Bulk Product 6217cc67 | Sports & Outdoors | $358.96 | 241 | ★ 4.8 | 43 | BULK-5565c036 |
| 6109 | Bulk Product 503e9e34 | Books | $676.18 | 53 | ★ 2.2 | 97 | BULK-2aaefb19 |
// 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
};
}