3

I'm having trouble with creating a LINQ query with IN parameters.
Corresponding SQL Query is

SELECT * FROM TABLEDEMO WHERE ID IN(SELECT ID FROM TABLE2)

How do I achieve the same using LINQ?
I can also take a list variable to store multiple IDs.

 (from x in objEntity.TABLEDEMO
 where x.TABLEDEMO (here should be the in parameter)
 select x);

3 Answers 3

3

You need to use Contains:

from x in objEntity.TABLEDEMO
where objEntity.Table2.Contains(y => y.ID == x.ID)
select x;

You can't write this any other, i.e. there is no query style operator you can use.

Sign up to request clarification or add additional context in comments.

Comments

3
from x in objEntity.Tabledemo
where (from y in objEntity.table2
       select ID).contains(x.ID)
select x

Comments

1

Use the Any operator:

from x in objEntity.TABLEDEMO
where otherQuery.Any(oq => oq == x.ID)
select x

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.