Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 6960 | Bulk Product 3e04ec27 | Toys & Games | $326.09 | 317 | ★ 0.9 | 21 | BULK-99212706 |
| 6961 | Bulk Product 5997d5c3 | Clothing | $552.62 | 346 | ★ 2.4 | 10 | BULK-bac9e7fd |
| 6962 | Bulk Product bf000e78 | Home & Garden | $372.17 | 254 | ★ 3.3 | 23 | BULK-67a03121 |
| 6963 | Bulk Product 0703c147 | Electronics | $500.66 | 229 | ★ 2.6 | 89 | BULK-963e1288 |
| 6964 | Bulk Product 57fa8f8c | Clothing | $349.66 | 113 | ★ 1.5 | 0 | BULK-471bbb5d |
| 6965 | Bulk Product 9e8de18c | Home & Garden | $691.02 | 426 | ★ 3.8 | 38 | BULK-b51f2c75 |
| 6966 | Bulk Product 7b910928 | Clothing | $628.71 | 256 | ★ 4.7 | 86 | BULK-e33e77c3 |
| 6967 | Bulk Product 414d9fad | Sports & Outdoors | $161.95 | 328 | ★ 3.7 | 34 | BULK-285802d2 |
| 6968 | Bulk Product 2262aaa0 | Electronics | $299.50 | 185 | ★ 5.0 | 84 | BULK-a0117bee |
| 6969 | Bulk Product 80ce0afc | Sports & Outdoors | $157.38 | 135 | ★ 4.7 | 70 | BULK-fd47c239 |
| 6970 | Bulk Product 1b4124f1 | Home & Garden | $918.68 | 203 | ★ 2.3 | 47 | BULK-6f7c26b7 |
| 6971 | Bulk Product a399083d | Home & Garden | $96.41 | 433 | ★ 4.6 | 83 | BULK-b6b92f9e |
| 6972 | Bulk Product 6e9dd4f3 | Home & Garden | $908.23 | 397 | ★ 2.3 | 11 | BULK-17e4990a |
| 6973 | Bulk Product 10c774f4 | Toys & Games | $687.63 | 395 | ★ 4.3 | 35 | BULK-dace8b58 |
| 6974 | Bulk Product 628f4fe5 | Toys & Games | $242.65 | 135 | ★ 3.7 | 86 | BULK-5cd98958 |
| 6975 | Bulk Product dc801c52 | Toys & Games | $771.74 | 214 | ★ 3.8 | 38 | BULK-6cf4e205 |
| 6976 | Bulk Product f3e575b8 | Clothing | $15.45 | 128 | ★ 1.3 | 99 | BULK-e088563d |
| 6977 | Bulk Product 9c98602e | Clothing | $63.62 | 353 | ★ 2.7 | 27 | BULK-f11d9bce |
| 6978 | Bulk Product 46296eae | Electronics | $660.37 | 121 | ★ 3.4 | 27 | BULK-2b571b8a |
| 6979 | Bulk Product a60a27df | Home & Garden | $88.15 | 232 | ★ 0.4 | 81 | BULK-a682863d |
| 6980 | Bulk Product 34e49ed1 | Clothing | $860.01 | 27 | ★ 4.2 | 15 | BULK-ce0c3484 |
| 6981 | Bulk Product 0fda86b0 | Sports & Outdoors | $480.35 | 273 | ★ 2.0 | 32 | BULK-c6ad6afc |
| 6982 | Bulk Product 894e3b82 | Electronics | $704.24 | 202 | ★ 4.0 | 48 | BULK-6e6e4917 |
| 6983 | Bulk Product f2d05cd8 | Home & Garden | $449.45 | 479 | ★ 0.6 | 88 | BULK-0b6dc74c |
| 6984 | Bulk Product b7d59c28 | Sports & Outdoors | $882.13 | 38 | ★ 4.8 | 81 | BULK-2ae0695d |
// 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
};
}