Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 12860 | Bulk Product 0e772e4f | Electronics | $409.17 | 412 | ★ 0.2 | 15 | BULK-5a312b64 |
| 12861 | Bulk Product 03010b38 | Clothing | $796.78 | 194 | ★ 3.2 | 62 | BULK-87b3a701 |
| 12862 | Bulk Product 03d12a55 | Books | $727.76 | 199 | ★ 2.5 | 40 | BULK-32a4e1dc |
| 12863 | Bulk Product 6c87fae2 | Toys & Games | $267.08 | 465 | ★ 2.3 | 40 | BULK-398a38b1 |
| 12864 | Bulk Product 24c5eb42 | Sports & Outdoors | $301.87 | 398 | ★ 1.8 | 61 | BULK-7775074c |
| 12865 | Bulk Product eaeffaa2 | Home & Garden | $195.81 | 191 | ★ 3.9 | 39 | BULK-11895255 |
| 12866 | Bulk Product 44d213b6 | Clothing | $468.75 | 136 | ★ 1.5 | 36 | BULK-20c20f24 |
| 12867 | Bulk Product 6f489fbe | Home & Garden | $646.63 | 127 | ★ 3.8 | 54 | BULK-02f4435f |
| 12868 | Bulk Product c79538eb | Toys & Games | $992.58 | 245 | ★ 0.9 | 50 | BULK-8989b4b9 |
| 12869 | Bulk Product 5547a101 | Home & Garden | $734.36 | 99 | ★ 4.3 | 7 | BULK-734ab1ed |
| 12870 | Bulk Product a8165bb1 | Toys & Games | $935.16 | 184 | ★ 2.6 | 44 | BULK-8cc24fd9 |
| 12871 | Bulk Product 0f33f56e | Sports & Outdoors | $46.13 | 150 | ★ 2.7 | 16 | BULK-29474dd0 |
| 12872 | Bulk Product defb407d | Clothing | $272.92 | 291 | ★ 0.5 | 12 | BULK-93408fb1 |
| 12873 | Bulk Product f913fecd | Home & Garden | $523.13 | 338 | ★ 2.5 | 6 | BULK-75c8f99c |
| 12874 | Bulk Product 4ae38fd2 | Toys & Games | $988.20 | 221 | ★ 4.9 | 54 | BULK-b9776f20 |
| 12875 | Bulk Product 9f363c9a | Sports & Outdoors | $17.27 | 348 | ★ 4.6 | 54 | BULK-756b1dd8 |
| 12876 | Bulk Product dd5ccbb2 | Books | $36.45 | 8 | ★ 2.9 | 22 | BULK-37bb006d |
| 12877 | Bulk Product 90c56645 | Books | $374.70 | 306 | ★ 1.9 | 3 | BULK-c9e648e6 |
| 12878 | Bulk Product 31607b63 | Books | $114.20 | 344 | ★ 1.7 | 85 | BULK-559abded |
| 12879 | Bulk Product d64867f2 | Books | $193.16 | 391 | ★ 0.3 | 26 | BULK-f114017b |
| 12880 | Bulk Product e259c15a | Sports & Outdoors | $528.44 | 27 | ★ 3.5 | 78 | BULK-afbdbe80 |
| 12881 | Bulk Product f75359fb | Electronics | $683.94 | 261 | ★ 4.7 | 11 | BULK-8133b0ad |
| 12882 | Bulk Product 2c7b4ed4 | Electronics | $859.73 | 414 | ★ 3.1 | 81 | BULK-edefa231 |
| 12883 | Bulk Product cdd3100e | Sports & Outdoors | $541.32 | 111 | ★ 4.4 | 58 | BULK-8ec83988 |
| 12884 | Bulk Product a56c5814 | Electronics | $661.19 | 197 | ★ 4.2 | 69 | BULK-e21f15de |
// 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
};
}