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

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -