Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 17960 | Bulk Product 1944520f | Home & Garden | $250.01 | 273 | ★ 2.0 | 23 | BULK-1ade370c |
| 17961 | Bulk Product 71bcff83 | Electronics | $604.92 | 258 | ★ 4.8 | 60 | BULK-2cf9321c |
| 17962 | Bulk Product 17b16267 | Home & Garden | $817.88 | 334 | ★ 4.8 | 40 | BULK-4edb3390 |
| 17963 | Bulk Product 89741a78 | Electronics | $974.21 | 57 | ★ 0.4 | 65 | BULK-99576326 |
| 17964 | Bulk Product 3e66f776 | Books | $505.34 | 209 | ★ 2.2 | 27 | BULK-57007bcc |
| 17965 | Bulk Product 2c9e36b2 | Toys & Games | $120.72 | 144 | ★ 0.2 | 45 | BULK-e0e4ed93 |
| 17966 | Bulk Product 4317e5f8 | Clothing | $876.17 | 149 | ★ 0.4 | 54 | BULK-394ba0e6 |
| 17967 | Bulk Product 958dbdba | Books | $813.47 | 146 | ★ 1.4 | 51 | BULK-242cf1ac |
| 17968 | Bulk Product d92d4c00 | Books | $322.56 | 213 | ★ 2.3 | 13 | BULK-bff26a0a |
| 17969 | Bulk Product 7a79638c | Toys & Games | $429.94 | 17 | ★ 2.9 | 31 | BULK-263af380 |
| 17970 | Bulk Product 33c7071e | Electronics | $118.54 | 405 | ★ 4.2 | 29 | BULK-20ef9f9c |
| 17971 | Bulk Product 8879762a | Electronics | $306.38 | 420 | ★ 0.6 | 48 | BULK-f38e7c39 |
| 17972 | Bulk Product 0a55efc1 | Sports & Outdoors | $743.88 | 131 | ★ 4.5 | 98 | BULK-a2c37338 |
| 17973 | Bulk Product cd9205ac | Toys & Games | $509.61 | 164 | ★ 4.3 | 0 | BULK-233c8a40 |
| 17974 | Bulk Product fa4aa882 | Sports & Outdoors | $63.67 | 121 | ★ 0.7 | 4 | BULK-e83bee65 |
| 17975 | Bulk Product 8f07ee93 | Books | $305.19 | 59 | ★ 2.8 | 16 | BULK-0a5d7fcd |
| 17976 | Bulk Product 0a73b46a | Toys & Games | $90.99 | 467 | ★ 0.4 | 28 | BULK-d4e12edb |
| 17977 | Bulk Product fe7de73f | Clothing | $858.05 | 301 | ★ 0.0 | 63 | BULK-bee9c870 |
| 17978 | Bulk Product aa2379a3 | Sports & Outdoors | $290.99 | 257 | ★ 1.5 | 30 | BULK-79fa4858 |
| 17979 | Bulk Product 2369e855 | Electronics | $736.16 | 321 | ★ 0.5 | 46 | BULK-9f7d902f |
| 17980 | Bulk Product db57de0f | Sports & Outdoors | $738.06 | 128 | ★ 0.6 | 45 | BULK-fa698a3e |
| 17981 | Bulk Product 29456f1a | Sports & Outdoors | $258.25 | 367 | ★ 4.7 | 53 | BULK-ee330586 |
| 17982 | Bulk Product 0f2df911 | Clothing | $179.94 | 151 | ★ 3.9 | 95 | BULK-a93436d6 |
| 17983 | Bulk Product f5dea86d | Books | $740.43 | 373 | ★ 0.5 | 28 | BULK-3d703ce7 |
| 17984 | Bulk Product 8c2ca2ab | Sports & Outdoors | $595.05 | 45 | ★ 2.9 | 89 | BULK-ef9aeb48 |
// 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
};
}