Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 9435 | Bulk Product 39a1c00f | Toys & Games | $106.85 | 70 | ★ 4.3 | 29 | BULK-1743a5fc |
| 9436 | Bulk Product 1b6f4e66 | Electronics | $705.71 | 128 | ★ 1.9 | 56 | BULK-cd04df5b |
| 9437 | Bulk Product 25ed5581 | Books | $172.01 | 352 | ★ 2.2 | 29 | BULK-4e0f9f6d |
| 9438 | Bulk Product 0e26c951 | Electronics | $155.69 | 196 | ★ 1.1 | 67 | BULK-70710ef0 |
| 9439 | Bulk Product 9122ae4a | Books | $261.17 | 22 | ★ 2.6 | 78 | BULK-f26025b2 |
| 9440 | Bulk Product 0f3a88ae | Toys & Games | $356.99 | 380 | ★ 0.8 | 27 | BULK-04306442 |
| 9441 | Bulk Product 770b3773 | Electronics | $166.70 | 154 | ★ 5.0 | 56 | BULK-50da696f |
| 9442 | Bulk Product a6f91df0 | Home & Garden | $541.75 | 130 | ★ 1.5 | 2 | BULK-112ba817 |
| 9443 | Bulk Product fa21b7bc | Books | $210.64 | 332 | ★ 3.3 | 20 | BULK-108c97fe |
| 9444 | Bulk Product 1d5df0ae | Toys & Games | $763.77 | 340 | ★ 3.5 | 10 | BULK-4d5b304e |
| 9445 | Bulk Product 2c6ea365 | Books | $186.79 | 395 | ★ 1.7 | 17 | BULK-09e1c6a0 |
| 9446 | Bulk Product c307eedb | Electronics | $981.32 | 463 | ★ 1.6 | 92 | BULK-ee437a03 |
| 9447 | Bulk Product f59bde97 | Sports & Outdoors | $526.02 | 234 | ★ 0.5 | 97 | BULK-524b58c4 |
| 9448 | Bulk Product b2b02423 | Sports & Outdoors | $575.43 | 47 | ★ 3.0 | 75 | BULK-b08a56df |
| 9449 | Bulk Product 86ef7e0e | Toys & Games | $25.18 | 168 | ★ 4.2 | 63 | BULK-c146e4d0 |
| 9450 | Bulk Product d838d359 | Electronics | $646.31 | 250 | ★ 5.0 | 11 | BULK-2003e102 |
| 9451 | Bulk Product 4c071e10 | Books | $50.24 | 347 | ★ 0.8 | 68 | BULK-ff11abff |
| 9452 | Bulk Product dc2878de | Electronics | $488.30 | 270 | ★ 1.5 | 4 | BULK-ea51f51c |
| 9453 | Bulk Product 4bdf3b6f | Toys & Games | $769.59 | 292 | ★ 0.1 | 23 | BULK-ea5b2e75 |
| 9454 | Bulk Product fed9a9d4 | Books | $460.34 | 364 | ★ 0.8 | 84 | BULK-8e98476c |
| 9455 | Bulk Product df3fd2b5 | Sports & Outdoors | $533.71 | 245 | ★ 2.3 | 11 | BULK-82cd26d7 |
| 9456 | Bulk Product 7cc38f2b | Toys & Games | $864.11 | 201 | ★ 1.4 | 34 | BULK-efbb02bc |
| 9457 | Bulk Product 9373b81c | Sports & Outdoors | $62.51 | 488 | ★ 2.0 | 4 | BULK-3129dc3e |
| 9458 | Bulk Product 82089bdd | Clothing | $440.89 | 123 | ★ 1.5 | 95 | BULK-c71b7e9a |
| 9459 | Bulk Product e48009b0 | Books | $710.92 | 289 | ★ 1.5 | 65 | BULK-4321b3ab |
// 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
};
}