title: How to correctly select data from LINQ to Entities expression?
body: <p>I have two entities: Document and Attachment. One document might have several or no Attachments. I need to receive an IQueryable that will allow me to always select entries both for document and all of its attachments.</p>
  
  <p>Here is the initial query but it selects only Attachments. For example, if I have 1 doc with 2 attachments it will select 2 entries, but I need to have 1 + 2 = 3 entries in this case.</p>
  
  <pre><code>from d in Documents
  from at in Attachments.Where(a=&gt;a.DocumentID == d.ID).DefaultIfEmpty(null)
  where d.StatusID != -1 &amp;&amp; d.ID == 1
  select new Result { ID = d.ID, AttachID = at?.ID };
  </code></pre>
  
  <p>Currently I will receive pure Document entry only if it don't have any attachments. Is it possible to always include additional entry for Document even if it has some attachments?</p>