c# - Linq select records that match a list of IDs -
is possible change query below, uses types
list within 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 have like:
list<int> types = new list<int> { 9, 15, 16 }; var cust = db.customers.where(x => types.contains(x.type_id).tolist();
(type_id not primary key).
thank you,
mark
yes, method list<t>.contains
translated sql in operator:
var cust = db.customers.where(x => types.contains(x.type_id)).tolist();
generated query like:
select * customers type_id in (@p0, @p1, @p2)
Comments
Post a Comment