title: Unable to cast the type 'x' to type 'y'. LINQ to Entities only supports casting EDM primitive or enumeration types
body: <p>I have classes that drive from Base class "<strong>BaseTask</strong>"</p>
  
  <ul>
  <li>Task1</li>
  <li>Task2</li>
  <li><p>Task3</p>
  
  <pre><code>  return DbContext.Projects.Include(t =&gt; t.Tasks).Select(p =&gt; new ProjectDto
      {
          Id = p.Id,
          Name = p.Name,
          Tasks = p.Tasks.Select(t =&gt; new TaskDto()
          {
              Id = t.Id,
              Name = t.Name,
              ProjectId = t.ProjectId,
              Selector = !(t is Task1) ? t.Selector : null,
              Task2Property = (t is Task2) ? ((Task2)t).Task2Property : null,
              SelectorPosition = (t is Task3) ? ((Task3)t).SelectorPosition : null,
              KeyId = t.KeyId
          }).ToList()
      }
      );
  </code></pre></li>
  </ul>
  
  <p>This part of the code returns the following error:</p>
  
  <blockquote>
    <p>Unable to cast the type 'Task' to type 'Task1'. LINQ to Entities only supports casting EDM primitive or enumeration types.</p>
  </blockquote>
  
  <p>how can I fix this issue?</p>