Kum*_*wal 6 entity-framework-core
我想将此SQL查询转换为Entity Framework Core 2.0查询。
SELECT *
FROM Product
WHERE ProdID IN (1,2,3);
Run Code Online (Sandbox Code Playgroud)
Mar*_*dle 20
根据对该问题的评论,您在 EF Core 中执行此操作的方式与 LINQ-to-SQL 相同:Enumerable.Contains对Where表达式中的数组使用扩展方法。
public async Task<List<Product>> GetProducts(params int[] ids)
{
return await context.Products
.Where(p => ids.Contains(p.ProdID)) // Enumerable.Contains extension method
.ToListAsync();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2399 次 |
| 最近记录: |