title: Linq GroupBy With Passed Where Predicate
body: <p>This works fine.<code>g.Key</code> is not null and has appropriate data:</p>
  
  <pre><code>var result = db.JournalEntries.Include(je =&gt; je.JournalRecords.Select(jr =&gt; jr.Account).Select(j =&gt; j.AccountParticulars))
                  .Where(je =&gt; je.Date &gt;= existingLedgerTransaction.From &amp;&amp; je.Date &lt;= existingLedgerTransaction.To)
                  .SelectMany(s =&gt; s.JournalRecords)
                  .GroupBy(d =&gt; d.AccountParticular.Account.AccountCategory)
                  .Select(g =&gt; new { Name = g.Key.Name });
  </code></pre>
  
  <p>But this does not work as <code>g.Key</code> is null:</p>
  
  <pre><code>var DateFilter = new Func&lt;JournalEntry, bool&gt;(je =&gt; je.Date &gt;= existingLedgerTransaction.From &amp;&amp; je.Date &lt;= existingLedgerTransaction.To);
  
  var result = db.JournalEntries.Include(je =&gt; je.JournalRecords.Select(jr =&gt; jr.Account).Select(j =&gt; j.AccountParticulars))
                  .Where(DateFilter)
                  .SelectMany(s =&gt; s.JournalRecords)
                  .GroupBy(d =&gt; d.AccountParticular.Account.AccountCategory)
                  .Select(g =&gt; new { Name = g.Key.Name });
  </code></pre>
  
  <p>I tried the same thing in a simple console app with static collection and passing in predicate works fine. What could be the problem here?</p>
  
  <p>NOTE: Lazy loading/dynamic proxy is disabled</p>