Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 6935 | Bulk Product 2696e42e | Sports & Outdoors | $901.14 | 34 | ★ 0.7 | 15 | BULK-89d80d3a |
| 6936 | Bulk Product ae600b2e | Clothing | $196.53 | 407 | ★ 1.7 | 48 | BULK-9da41933 |
| 6937 | Bulk Product 14339a8b | Sports & Outdoors | $440.46 | 483 | ★ 0.0 | 96 | BULK-ad34f0f9 |
| 6938 | Bulk Product bc071f5f | Home & Garden | $111.37 | 326 | ★ 1.2 | 37 | BULK-ef177441 |
| 6939 | Bulk Product cbf0b61b | Toys & Games | $933.08 | 16 | ★ 3.8 | 78 | BULK-166dfef5 |
| 6940 | Bulk Product ea1b5d33 | Sports & Outdoors | $472.41 | 115 | ★ 1.6 | 25 | BULK-28fae47f |
| 6941 | Bulk Product 23316cee | Home & Garden | $959.34 | 211 | ★ 1.8 | 96 | BULK-d15ceae8 |
| 6942 | Bulk Product 716cd788 | Clothing | $287.58 | 208 | ★ 2.5 | 30 | BULK-159907a1 |
| 6943 | Bulk Product fc9fd896 | Clothing | $536.37 | 374 | ★ 1.5 | 70 | BULK-1be937c4 |
| 6944 | Bulk Product 86f2ba11 | Sports & Outdoors | $759.56 | 311 | ★ 3.9 | 42 | BULK-776d4181 |
| 6945 | Bulk Product d41a9150 | Toys & Games | $516.54 | 141 | ★ 3.6 | 64 | BULK-8ab6a5ac |
| 6946 | Bulk Product 899b5172 | Toys & Games | $707.43 | 237 | ★ 2.0 | 64 | BULK-270a56d4 |
| 6947 | Bulk Product 13b1bf02 | Sports & Outdoors | $215.97 | 5 | ★ 0.3 | 65 | BULK-29a13f0f |
| 6948 | Bulk Product 378c893c | Clothing | $309.22 | 135 | ★ 0.4 | 97 | BULK-6b8c879c |
| 6949 | Bulk Product 69710434 | Sports & Outdoors | $901.02 | 445 | ★ 0.6 | 11 | BULK-8a8960b3 |
| 6950 | Bulk Product 95add044 | Books | $754.91 | 177 | ★ 0.9 | 56 | BULK-f4ee8d38 |
| 6951 | Bulk Product b9ef3b19 | Toys & Games | $588.56 | 131 | ★ 2.9 | 97 | BULK-58f942b6 |
| 6952 | Bulk Product 1757eccf | Books | $307.57 | 303 | ★ 2.3 | 55 | BULK-2849424b |
| 6953 | Bulk Product 2ff53b7e | Toys & Games | $143.09 | 385 | ★ 3.6 | 11 | BULK-f15105ea |
| 6954 | Bulk Product be6b73e8 | Toys & Games | $448.23 | 73 | ★ 3.1 | 95 | BULK-9a893acd |
| 6955 | Bulk Product ba47267a | Clothing | $639.97 | 452 | ★ 2.3 | 59 | BULK-5efa696e |
| 6956 | Bulk Product 2543cdb3 | Clothing | $549.56 | 313 | ★ 2.5 | 30 | BULK-2b376164 |
| 6957 | Bulk Product ec46e1de | Clothing | $866.40 | 399 | ★ 3.7 | 28 | BULK-a64ab6cb |
| 6958 | Bulk Product 3db2505f | Home & Garden | $868.72 | 485 | ★ 4.2 | 47 | BULK-e1e5451b |
| 6959 | Bulk Product 858b9906 | Toys & Games | $139.26 | 33 | ★ 2.5 | 4 | BULK-2e6dab74 |
// 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
};
}