Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 6710 | Bulk Product 70e761b9 | Electronics | $1,005.37 | 351 | ★ 3.4 | 99 | BULK-ae4df151 |
| 6711 | Bulk Product f763506d | Clothing | $569.04 | 194 | ★ 3.5 | 75 | BULK-3672d1bd |
| 6712 | Bulk Product fb09613a | Sports & Outdoors | $193.00 | 488 | ★ 1.9 | 82 | BULK-0202cbab |
| 6713 | Bulk Product 4b9004f5 | Sports & Outdoors | $156.69 | 322 | ★ 1.6 | 85 | BULK-287fa687 |
| 6714 | Bulk Product 96c51e0a | Books | $77.92 | 105 | ★ 4.7 | 65 | BULK-c3f7d7e2 |
| 6715 | Bulk Product fa9df2c0 | Clothing | $297.74 | 351 | ★ 4.9 | 76 | BULK-e4ff2a7c |
| 6716 | Bulk Product 1c9ede80 | Home & Garden | $279.65 | 155 | ★ 2.5 | 31 | BULK-3ac2cc58 |
| 6717 | Bulk Product 5363f65c | Electronics | $471.07 | 224 | ★ 3.4 | 68 | BULK-2a8a13c9 |
| 6718 | Bulk Product 9eb139cb | Electronics | $962.94 | 116 | ★ 1.4 | 88 | BULK-9e4220f7 |
| 6719 | Bulk Product 7c18195c | Home & Garden | $128.50 | 70 | ★ 3.3 | 93 | BULK-73d6ffd7 |
| 6720 | Bulk Product db8275ae | Books | $629.23 | 258 | ★ 3.6 | 45 | BULK-81925b97 |
| 6721 | Bulk Product 879e2477 | Home & Garden | $959.26 | 258 | ★ 3.4 | 89 | BULK-170c1721 |
| 6722 | Bulk Product 72e93f1b | Clothing | $120.87 | 291 | ★ 4.0 | 28 | BULK-2aaa536c |
| 6723 | Bulk Product ca49c797 | Electronics | $670.30 | 375 | ★ 4.4 | 95 | BULK-ddcaa3bf |
| 6724 | Bulk Product ee1eed53 | Toys & Games | $726.37 | 246 | ★ 4.0 | 5 | BULK-5b03220d |
| 6725 | Bulk Product 97699d55 | Toys & Games | $421.86 | 235 | ★ 3.6 | 84 | BULK-820b85fc |
| 6726 | Bulk Product 5fc1a195 | Sports & Outdoors | $886.71 | 73 | ★ 1.6 | 93 | BULK-319ce72f |
| 6727 | Bulk Product 307a218e | Home & Garden | $852.18 | 243 | ★ 1.0 | 15 | BULK-8b2c5713 |
| 6728 | Bulk Product fd1a071e | Electronics | $922.54 | 71 | ★ 1.4 | 35 | BULK-4a31f5f7 |
| 6729 | Bulk Product cf8732f9 | Books | $276.46 | 341 | ★ 4.8 | 18 | BULK-59305764 |
| 6730 | Bulk Product 4d5537c2 | Books | $511.29 | 189 | ★ 0.8 | 63 | BULK-d6a749eb |
| 6731 | Bulk Product 8d47051c | Clothing | $71.07 | 437 | ★ 0.8 | 13 | BULK-906a7266 |
| 6732 | Bulk Product b233946a | Sports & Outdoors | $628.54 | 198 | ★ 1.6 | 91 | BULK-12f10b0d |
| 6733 | Bulk Product dea9b847 | Sports & Outdoors | $697.08 | 77 | ★ 1.0 | 38 | BULK-6f454617 |
| 6734 | Bulk Product dbdd53f4 | Clothing | $632.90 | 191 | ★ 0.8 | 4 | BULK-ed1257c8 |
// 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
};
}