Linq - EntityFramework NotSupportedException
<p>I have a query that looks like this:</p>

<pre><code>var caseList = (from x in context.Cases
         where allowedCaseIds.Contains(x =&gt; x.CaseId)
         select new Case {
            CaseId = x.CaseId,
            NotifierId = x.NotifierId,
            Notifier = x.NotifierId.HasValue ? new Notifier { Name = x.Notifier.Name } : null // This line throws exception
         }).ToList();
</code></pre>

<p>A <code>Case</code> class can have 0..1 <code>Notifier</code></p>

<p>The query above will result in the following <code>System.NotSupportedException</code>:</p>

<blockquote>
  <p>Unable to create a null constant value of type 'Models.Notifier'. Only entity types, enumeration types or primitive types are supported
  in this context.</p>
</blockquote>

<p>At the moment the only workaround I found is to loop the query result afterwards and manually populate <code>Notifier</code>like this:</p>

<pre><code>foreach (var c in caseList.Where(x =&gt; x.NotifierId.HasValue)
{
    c.Notifier = (from x in context.Notifiers 
                 where x.CaseId == c.CaseId
                 select new Notifier {
                     Name = x.Name
                 }).FirstOrDefault();
}
</code></pre>

<p>But I really don't want to do this because in my actual scenario it would generate hundreds of additional queries.</p>

<p>Is there any possible solution for a situation like this?. </p>