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();
}
See related LINQ to Entities question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With