title: How to output results when Inheritance used in Entity Framework (Discriminator)
body: <p>I have 4 classes that drive from a base class.</p>
  
  <p>The sub classes has some extra properties. And this results in a single combined table in the database with an extra column 'Discriminator'. This is done automatically by EF to identify the type of the object when the data is loaded back.</p>
  
  <p><strong>BaseTask</strong> is the base class</p>
  
  <pre><code>Task1 
  Task2
  Task3
  Task4 
  </code></pre>
  
  <p>Task1 class has a property called  <strong>SpecialKey</strong>.
  the classes drives from BaseTask</p>
  
  <p>So now I would like to list all the objects from table to a UI.</p>
  
  <p>When I load the table results as below:</p>
  
  <pre><code>var tasks = DbContext.BaseTasks.ToList();
  
  foreach(var task in tasks){
  
  // output all columns details from BaseTask table from database
  }
  </code></pre>
  
  <p>But as you can see that because <strong>SpecialKey</strong> is not part of the base class I cannot output that property.</p>
  
  <p>How can I overcome this problem? </p>
  
  <p>Do I really have to do the following?</p>
  
  <pre><code>    var tasks = DbContext.BaseTasks.ToList();
  
          foreach(var task in tasks.OfType&lt;Task1&gt;){
          // output task 1 details
          }
  
          foreach(var task in tasks.OfType&lt;Task2&gt;){
          // output task 2 details
          }
  
          foreach(var task in tasks.OfType&lt;Task3&gt;){
          // output task 3 details
          }
  </code></pre>
  
  <p>etc...
  This looks really messy. This really tells me that inheritance was not a good idea to create table objects.  </p>