title: Adding functionality to a LINQ query
body: <p>I have this query:</p>
  
  <pre><code>from p in IPACS_Procedures
  where !(from pd in IPACS_ProcedureDocs
         join d in IPACS_Documents on pd.DocumentID equals d.DocumentID
         where d.DateDeleted == null &amp;&amp; d.DateApproved != null
         select pd.ProcedureID).Contains(p.ProcedureID)
  select new { p.ProcedureID, p.Name }
  </code></pre>
  
  <p>The above works but we have a version control system in place.  I need to add in the ability to check if there is a version with a higher version that is not yet approved.</p>
  
  <p>The above code looks for any <code>document (d)</code> that is not marked as Deleted <code>(DateDelete)</code> and it has been approved <code>(DateApproved)</code>.</p>
  
  <p>I need to add in the ability to check the Versions table to see if there is an unapproved version and if it has been marked as deleted or not.</p>
  
  <p>After many attempts I cannot seem to get this to work.</p>
  
  <pre><code>d.IPACS_Versions.Where(v =&gt; v.revision &gt; d.revision &amp;&amp; v.dateDeleted == null)
  </code></pre>
  
  <p>Specifics:</p>
  
  <pre><code>d.DateDeleted must equal null to be valid
  d.DateApproved must not be null to be valid
  
  d will always have a record in IPACS_Versions but if the record in IPACS_Version 
  has a higher revision than d.revision and if the higher version then dateDeleted 
  must be null to be valid in the above list.
  </code></pre>