Efficient pagination using OFFSET-FETCH on SQL Server.
| ID | Name | Category | Price | Stock | Rating | Reviews | SKU |
|---|---|---|---|---|---|---|---|
| 7135 | Bulk Product 45d4dc0f | Home & Garden | $614.54 | 172 | ★ 4.2 | 12 | BULK-80302154 |
| 7136 | Bulk Product 4dce59f6 | Home & Garden | $786.97 | 346 | ★ 1.1 | 16 | BULK-015f179d |
| 7137 | Bulk Product 507b6b48 | Toys & Games | $661.87 | 360 | ★ 0.5 | 15 | BULK-15819d47 |
| 7138 | Bulk Product 7754c9e8 | Clothing | $990.87 | 52 | ★ 2.3 | 19 | BULK-622f36af |
| 7139 | Bulk Product 3abadae8 | Toys & Games | $426.17 | 286 | ★ 4.3 | 78 | BULK-4dbaa943 |
| 7140 | Bulk Product a34e7b55 | Books | $302.82 | 3 | ★ 0.4 | 47 | BULK-d56949d4 |
| 7141 | Bulk Product cccbbf47 | Books | $607.82 | 482 | ★ 0.2 | 5 | BULK-0afeb63f |
| 7142 | Bulk Product 45d658a8 | Electronics | $795.60 | 406 | ★ 3.8 | 4 | BULK-6fa4d58f |
| 7143 | Bulk Product 39532ad4 | Electronics | $376.81 | 285 | ★ 1.2 | 93 | BULK-791aa8b8 |
| 7144 | Bulk Product 4b4f7261 | Sports & Outdoors | $418.68 | 447 | ★ 0.3 | 19 | BULK-6c09a624 |
| 7145 | Bulk Product 6c966eb3 | Toys & Games | $836.34 | 112 | ★ 2.0 | 29 | BULK-d98a39c1 |
| 7146 | Bulk Product 5d29f12e | Clothing | $896.17 | 90 | ★ 2.0 | 22 | BULK-77b6f112 |
| 7147 | Bulk Product 7aab8855 | Sports & Outdoors | $204.76 | 87 | ★ 2.5 | 66 | BULK-199f1560 |
| 7148 | Bulk Product c14a6425 | Toys & Games | $943.89 | 0 | ★ 1.4 | 5 | BULK-5ea03892 |
| 7149 | Bulk Product dc5d14f0 | Sports & Outdoors | $239.08 | 331 | ★ 4.0 | 94 | BULK-88bb193b |
| 7150 | Bulk Product 27570ce2 | Toys & Games | $790.40 | 359 | ★ 3.9 | 2 | BULK-bfbdde6e |
| 7151 | Bulk Product b7986e05 | Electronics | $396.26 | 3 | ★ 1.6 | 39 | BULK-5d6222f1 |
| 7152 | Bulk Product a6d4c3ce | Clothing | $844.61 | 441 | ★ 2.7 | 62 | BULK-7278f70a |
| 7153 | Bulk Product ad149cf9 | Clothing | $654.47 | 124 | ★ 0.6 | 29 | BULK-249c6108 |
| 7154 | Bulk Product ee9d7703 | Electronics | $68.27 | 341 | ★ 3.3 | 40 | BULK-866846ef |
| 7155 | Bulk Product 860a8d70 | Clothing | $463.87 | 438 | ★ 2.2 | 81 | BULK-17045e36 |
| 7156 | Bulk Product a71c83d1 | Home & Garden | $786.85 | 196 | ★ 0.6 | 47 | BULK-da1b4bbb |
| 7157 | Bulk Product 9ec71c28 | Toys & Games | $215.90 | 290 | ★ 0.7 | 71 | BULK-39b961ef |
| 7158 | Bulk Product 9f44b6fb | Sports & Outdoors | $173.26 | 94 | ★ 5.0 | 9 | BULK-5373786a |
| 7159 | Bulk Product 504b6a46 | Electronics | $270.95 | 297 | ★ 4.4 | 22 | BULK-ef6e02fa |
// 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
};
}