Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 10035 | Bulk Product 9e78dd51 | Sports & Outdoors | $735.85 | 57 | ★ 0.3 | 6 | BULK-61cbf29b |
| 10036 | Bulk Product f115aa8b | Sports & Outdoors | $990.20 | 446 | ★ 1.5 | 97 | BULK-2e5dc9a5 |
| 10037 | Bulk Product 3f4510cf | Electronics | $240.86 | 490 | ★ 2.1 | 14 | BULK-72ffda81 |
| 10038 | Bulk Product e2a9dbbc | Toys & Games | $763.45 | 36 | ★ 2.3 | 39 | BULK-69f7195f |
| 10039 | Bulk Product d8c97cf5 | Electronics | $276.16 | 160 | ★ 0.6 | 44 | BULK-bf21acb8 |
| 10040 | Bulk Product 18da4b20 | Home & Garden | $261.27 | 138 | ★ 1.9 | 73 | BULK-27678f67 |
| 10041 | Bulk Product 0f25ba0e | Electronics | $595.82 | 33 | ★ 2.0 | 2 | BULK-e82a2ecf |
| 10042 | Bulk Product 4b0b15f3 | Clothing | $445.90 | 297 | ★ 2.0 | 81 | BULK-ee164375 |
| 10043 | Bulk Product 41730bbf | Books | $529.23 | 7 | ★ 0.4 | 27 | BULK-03e90d24 |
| 10044 | Bulk Product 3ef39d20 | Clothing | $295.96 | 180 | ★ 2.6 | 22 | BULK-3a87ccdb |
| 10045 | Bulk Product 5758905c | Electronics | $343.03 | 360 | ★ 1.2 | 19 | BULK-38a3e1a4 |
| 10046 | Bulk Product 551bddb7 | Electronics | $277.67 | 297 | ★ 3.6 | 76 | BULK-78dde8f7 |
| 10047 | Bulk Product fd8b37de | Home & Garden | $278.79 | 316 | ★ 0.7 | 56 | BULK-00e54a4b |
| 10048 | Bulk Product 13f98da8 | Home & Garden | $978.23 | 105 | ★ 4.6 | 31 | BULK-441a37b6 |
| 10049 | Bulk Product 256b046d | Clothing | $723.75 | 13 | ★ 4.4 | 89 | BULK-02b42655 |
| 10050 | Bulk Product dc60633f | Sports & Outdoors | $512.23 | 335 | ★ 4.7 | 28 | BULK-eb509297 |
| 10051 | Bulk Product 8390c593 | Toys & Games | $842.98 | 374 | ★ 3.4 | 60 | BULK-1bbc8a19 |
| 10052 | Bulk Product 661c81b3 | Books | $86.13 | 176 | ★ 4.7 | 71 | BULK-8fe4575e |
| 10053 | Bulk Product a28e1af8 | Toys & Games | $571.01 | 172 | ★ 0.4 | 13 | BULK-eb7ad5df |
| 10054 | Bulk Product 0810a311 | Electronics | $546.74 | 248 | ★ 1.8 | 45 | BULK-c1f6ddd6 |
| 10055 | Bulk Product 6d82f425 | Home & Garden | $136.62 | 346 | ★ 0.2 | 57 | BULK-a2c807de |
| 10056 | Bulk Product b9ea7e7d | Clothing | $826.11 | 370 | ★ 1.3 | 16 | BULK-2a063b18 |
| 10057 | Bulk Product b0ebd54f | Clothing | $802.61 | 79 | ★ 0.5 | 59 | BULK-adaae8e8 |
| 10058 | Bulk Product 0c0f01fc | Toys & Games | $121.97 | 3 | ★ 4.8 | 47 | BULK-c4f66807 |
| 10059 | Bulk Product a006b7a5 | Sports & Outdoors | $485.92 | 69 | ★ 4.5 | 4 | BULK-ad068491 |
// 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
};
}