title: Entity Framework: SELECT From Where ID NOT IN
body: <p>I know this could be easy question but I spent hours trying to figure it out with no luck!</p>
  
  <p>I want to achieve the following SQL Command in Entity Framework:</p>
  
  <pre><code>SELECT * FROM Table1
  WHERE RowID NOT IN (
  SELECT SomeID FROM Table2 Where SomeID is not null)
  </code></pre>
  
  <p>I tried the following (Asp.Net C#):</p>
  
  <pre><code>var SomeIDs = db.Table2.Where(n =&gt; n.SomeID != null).Select(x =&gt; x.SomeID);
  var query = (from a in db.Table1
               where !(SomeIDs.Contains(a.RowID))
               select a;
  </code></pre>
  
  <p>It works fine in small database, but in production db it takes forever then time out!</p>
  
  <p>Appreciate any help!</p>