title: Linq2Sql select records by multiple ids?
body: <p>For example, I have table with 10000000 records and list <strong>in memory</strong> with 100000 ids.</p>
  
  <p>How I can select all records by these ids?
  Obviously, I can do it like this:</p>
  
  <pre><code>var ids = GetIds();
  var result = from q in ctx.Records
               where ids.Contains(q.Id)
               select q;
  </code></pre>
  
  <p>But if I do it like this, it will have two problems:</p>
  
  <ul>
  <li><p>Monstrosity in generated SQL each time I use this query.</p></li>
  <li><p>O(N) complexety for each row. So, I will receive my result in couple of years.</p></li>
  </ul>
  
  <p>How I can do this? How is this done with <code>linq2sql</code> or is this impossible to bypass?</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <ul>
  <li>GetIds - this function returns about 100.000 ids. And no, I can't <strong>join</strong> it. <strong>It is calculated</strong>.</li>
  <li><p>Yes, I tested it, I debugged it and HAVE seen what is generated. It is something like this:</p>
  
  <pre><code>SELECT * FROM Records WHERE id IN (/*one hundreds of thousand goes here O_O*/)
  </code></pre>
  
  <p>Simple math: 10.000.000 x 100.000 will give 1.000.000.000.000 in time complexity. This is extremely unefficient.</p></li>
  </ul>