I want to convert this SQL query to an Entity Framework Core 2.0 query.
SELECT *
FROM Product
WHERE ProdID IN (1,2,3);
As per the comments on the question, the way you do this in EF Core is the same as for LINQ-to-SQL: use the Enumerable.Contains
extension method on an array in your Where
expression.
public async Task<List<Product>> GetProducts(params int[] ids)
{
return await context.Products
.Where(p => ids.Contains(p.ProdID)) // Enumerable.Contains extension method
.ToListAsync();
}
Contains
in Linq is a generic function taking a lambda as an argument...and can be of any type as inferred by the lambda itself.