title: LINQ exclude null while selecting into enumeration
body: <p>The data below is just is sample data</p>
  
  <pre><code>ID  BatchName       File
  ===========================
  1   Batch1          null 
  2   Batch2          "C:\File2_1.pdf"
  2   Batch2          "C:\File2_2.pdf"
  3   Batch3          "C:\File3_1.pdf"
  3   Batch3          "C:\File3_2.pdf"
  </code></pre>
  
  <p>Then i have a class that represents the above data</p>
  
  <pre><code>public class SourceBatch
  {
     public int ID {get;set;}
     public string BatchName {get;set;}
     public string File {get;set;}
  }
  </code></pre>
  
  <p>I want to group it by <code>ID</code> and <code>BatchName</code> and select all the <code>File</code> in that group into list. For that I have corresponding class</p>
  
  <pre><code>public class DestinationBatch
  {
     public int ID {get;set;}
     public string BatchName {get;set;}
     public IEnumerable&lt;string&gt; Files {get;set;} // this is list of string
  }
  </code></pre>
  
  <p>Below is the code which does that</p>
  
  <pre><code>IList&lt;SourceBatch&gt; list = GetSourceList();
  
  var result = list.GroupBy(x =&gt; new
  {
      ID = x.ID,
      BatchName = x.BatchName
  })
  .Select(y =&gt; new DestinationBatch()
  {
       ID = y.Key.ID,
       BatchName = y.Key.BatchName,
       Files = y.Select(z =&gt; z.File)
   }).ToList();
  </code></pre>
  
  <p>This is working fine except in one case.<br>
  For <code>Batch1</code> where <code>File</code> is null, its populating <code>Files</code> property with one null record. I dont want to include null file into <code>Files</code></p>