Is it possible to change my query below, so that it uses the types
list within a contains type query.
So instead of having:
var cust = db.Customers.Where(x => x.type_id==9 || x.type_id==15 || x.type_id==16).ToList();
...I would have something like:
List<int> types = new List<int> { 9, 15, 16 };
var cust = db.Customers.Where(x => types.contains(x.type_id).ToList();
(type_id is not the primary key).
Thank you,
Mark
Yes, method List<T>.Contains
will be translated into SQL IN operator:
var cust = db.Customers.Where(x => types.Contains(x.type_id)).ToList();
Generated query will look like:
SELECT * FROM Customers
WHERE type_id IN (@p0, @p1, @p2)
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