How to write sub queries like these in EF?
select * from table1 where col1 in (select col1 from table2 where col2 = 'xyz')
or
select * from table1 where col1 not in (select col1 from table2 where col2 = 'xyz')
I tried something like these
from t1 in table1
where (from t2 in table2 where col2 = 'xyz' select t2.col1).Contains(t1.col1)
select t1
and
from t1 in table1
where !(from t2 in table2 where col2 = 'xyz' select t2.col1).Contains(t1.col1)
select t1
these queries are working fine LinqPad or Linq to Sql
IN/NOT IN. I don't doubt that the real scenario is more complicated than your example - but I would suggest that you try to find a way to use simple joins, because they are easier to read/maintain and most often result in better performance (especiallyNOT IN, that's a scary one). Perhaps if you included a more specific example, somebody could help you with that.