title: Linq query optimization and method syntax equivalent
body: <p>I have these two queries :</p>
  
  <ol>
  <li>The first one gets a distinct list of identifiers.</li>
  <li><p>The second filter its result on these ids.</p>
  
  <pre><code>    var query = (from bk in context.BookKeeping
                   join bk12 in context.BookKeeping on bk.LetteringId equals bk12.LetteringId 
                   into bk11
                   from bk1 in bk11.DefaultIfEmpty()
                   join bi2 in context.BillingInformation on bk1.BillingInformationId equals bi2.BillId 
                   into bi1
                   from bi in bi1.DefaultIfEmpty()
                   where bk.LetteringId != null &amp;&amp; bk.PaymentId != null &amp;&amp; bk1.LetteringId != null
                   select bk.PaymentId).Distinct();
  
      var query2 = from m in context.Movement
                   join p2 in context.Payment on m.PaymentId equals p2.Id
                   into p1
                   from p in p1.DefaultIfEmpty()
                   join pm2 in context.PaymentMode on p.PaymentModeId equals pm2.Id
                   into pm1
                   from pm in pm1.DefaultIfEmpty()
                   from ids in query
                   where ids.Value == p.Id
                   select m;
  </code></pre></li>
  </ol>
  
  <p>The interesting part of the second query is following :</p>
  
  <pre><code>                 from ids in query
                   where ids.Value == p.Id
  </code></pre>
  
  <p>I would like to know if I could make it more compact and how to filter on a list of ids conditionnaly using the method syntax. I understand that I have to use <strong>SelectMany</strong> but don't know how to choose the right overload.</p>
  
  <p>TIA. </p>