Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 6485 | Bulk Product 61ca8edf | Clothing | $376.04 | 175 | ★ 2.1 | 95 | BULK-71a060cf |
| 6486 | Bulk Product 22c96d3d | Home & Garden | $17.26 | 35 | ★ 4.2 | 83 | BULK-dd66a973 |
| 6487 | Bulk Product cadda985 | Books | $220.70 | 6 | ★ 0.8 | 16 | BULK-6f209618 |
| 6488 | Bulk Product 0fbb47d9 | Sports & Outdoors | $564.83 | 50 | ★ 2.7 | 9 | BULK-5280d03d |
| 6489 | Bulk Product 6ce508c7 | Clothing | $76.05 | 420 | ★ 3.1 | 8 | BULK-2629a7bc |
| 6490 | Bulk Product b0669409 | Toys & Games | $788.29 | 88 | ★ 1.8 | 9 | BULK-67a4b591 |
| 6491 | Bulk Product 22b968ee | Books | $388.34 | 368 | ★ 3.6 | 29 | BULK-bc76650f |
| 6492 | Bulk Product ad1e53fe | Home & Garden | $263.08 | 264 | ★ 4.2 | 2 | BULK-9e9c41c8 |
| 6493 | Bulk Product f0c109e4 | Electronics | $400.92 | 346 | ★ 2.2 | 72 | BULK-04ed71c5 |
| 6494 | Bulk Product f86cdf58 | Sports & Outdoors | $625.10 | 247 | ★ 3.5 | 26 | BULK-92443511 |
| 6495 | Bulk Product 034e32d5 | Books | $681.47 | 16 | ★ 2.0 | 63 | BULK-71b88253 |
| 6496 | Bulk Product 2c682785 | Electronics | $543.21 | 111 | ★ 1.9 | 98 | BULK-834ff519 |
| 6497 | Bulk Product 5c3401ca | Sports & Outdoors | $322.36 | 374 | ★ 2.1 | 34 | BULK-ad128b04 |
| 6498 | Bulk Product 080a2dc9 | Home & Garden | $593.21 | 95 | ★ 0.8 | 61 | BULK-a079e764 |
| 6499 | Bulk Product f8cd8edf | Home & Garden | $89.45 | 56 | ★ 4.6 | 18 | BULK-b93bb375 |
| 6500 | Bulk Product 0b8af69f | Books | $887.81 | 145 | ★ 0.7 | 95 | BULK-dd7b2901 |
| 6501 | Bulk Product 4906c891 | Clothing | $810.99 | 138 | ★ 1.1 | 44 | BULK-a1d9fda1 |
| 6502 | Bulk Product 271ecbc1 | Toys & Games | $112.44 | 461 | ★ 4.0 | 66 | BULK-31c6431a |
| 6503 | Bulk Product c49db22d | Toys & Games | $276.87 | 178 | ★ 4.4 | 76 | BULK-3ea405f1 |
| 6504 | Bulk Product ae88812f | Clothing | $452.79 | 426 | ★ 1.2 | 65 | BULK-f3369209 |
| 6505 | Bulk Product 177a8e0f | Books | $422.14 | 23 | ★ 2.1 | 6 | BULK-77ce4172 |
| 6506 | Bulk Product d51579c8 | Books | $765.70 | 379 | ★ 1.9 | 5 | BULK-363506a5 |
| 6507 | Bulk Product cbf20747 | Home & Garden | $629.82 | 472 | ★ 2.0 | 54 | BULK-f536e56f |
| 6508 | Bulk Product 79b63189 | Electronics | $704.02 | 130 | ★ 4.5 | 42 | BULK-c620456f |
| 6509 | Bulk Product 98280338 | Clothing | $924.56 | 93 | ★ 1.4 | 34 | BULK-daa7f53c |
// 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
};
}