Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17235 | Bulk Product 92ab94ed | Books | $582.19 | 167 | ★ 1.1 | 39 | BULK-f78d0104 |
| 17236 | Bulk Product 579943ff | Clothing | $605.70 | 17 | ★ 2.3 | 32 | BULK-519fd1e5 |
| 17237 | Bulk Product f4b18e91 | Toys & Games | $98.27 | 301 | ★ 3.8 | 24 | BULK-16e0360b |
| 17238 | Bulk Product efcf03cc | Sports & Outdoors | $317.46 | 322 | ★ 4.0 | 40 | BULK-9b31ca4f |
| 17239 | Bulk Product a402c9cd | Electronics | $539.66 | 331 | ★ 0.2 | 8 | BULK-2f459ef9 |
| 17240 | Bulk Product 67549014 | Home & Garden | $89.61 | 388 | ★ 3.4 | 95 | BULK-c74f97f2 |
| 17241 | Bulk Product 8505a279 | Toys & Games | $806.26 | 160 | ★ 2.5 | 48 | BULK-a076d266 |
| 17242 | Bulk Product 31dda3d3 | Toys & Games | $301.84 | 496 | ★ 0.7 | 95 | BULK-33ea2ab5 |
| 17243 | Bulk Product 2da35bd8 | Home & Garden | $247.83 | 144 | ★ 1.0 | 8 | BULK-38a21f89 |
| 17244 | Bulk Product 8838cdf1 | Sports & Outdoors | $675.54 | 353 | ★ 4.1 | 35 | BULK-35dd3ef8 |
| 17245 | Bulk Product 0a7e0d12 | Electronics | $818.09 | 11 | ★ 3.0 | 58 | BULK-806918ff |
| 17246 | Bulk Product c722fe1c | Clothing | $160.92 | 9 | ★ 0.8 | 40 | BULK-df76c07c |
| 17247 | Bulk Product c03535af | Clothing | $88.86 | 443 | ★ 1.9 | 73 | BULK-6d482900 |
| 17248 | Bulk Product 2dc6e94a | Books | $771.24 | 296 | ★ 4.4 | 42 | BULK-02c08b06 |
| 17249 | Bulk Product f3c0e44a | Clothing | $593.70 | 260 | ★ 0.0 | 42 | BULK-2f6f2838 |
| 17250 | Bulk Product 1d2e3dba | Toys & Games | $556.19 | 333 | ★ 3.2 | 39 | BULK-5b56aec2 |
| 17251 | Bulk Product 110a0ff9 | Electronics | $830.51 | 254 | ★ 1.5 | 35 | BULK-bc1da8c0 |
| 17252 | Bulk Product 5739f623 | Electronics | $686.98 | 200 | ★ 2.6 | 51 | BULK-b7185a17 |
| 17253 | Bulk Product bddbc2f6 | Clothing | $945.41 | 361 | ★ 1.6 | 34 | BULK-c74071c8 |
| 17254 | Bulk Product 4ec48f68 | Electronics | $880.50 | 197 | ★ 2.4 | 32 | BULK-96d3ec55 |
| 17255 | Bulk Product 9c31a897 | Home & Garden | $568.59 | 390 | ★ 3.3 | 61 | BULK-6973d8be |
| 17256 | Bulk Product 98536d27 | Electronics | $128.88 | 263 | ★ 3.8 | 60 | BULK-b48a4ab3 |
| 17257 | Bulk Product 1387eacf | Electronics | $45.98 | 330 | ★ 4.5 | 41 | BULK-d23d8b35 |
| 17258 | Bulk Product 79de1e80 | Electronics | $263.06 | 92 | ★ 2.1 | 71 | BULK-3998d7e8 |
| 17259 | Bulk Product 093346d7 | Sports & Outdoors | $671.84 | 347 | ★ 4.7 | 53 | BULK-c500cc70 |
// 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
};
}