开发者

SQL 'IN' operator in LINQ to Entities

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.开发者_JAVA技巧

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


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.


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


Use the Any operator:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜