title: How does EF6 know derived type?
body: <p>I use Entity Framework 6 with Table-Per-Type inheritance approach. </p>
  
  <p>Tables look like this (just an example):</p>
  
  <pre><code>ConfigurationKeys
    ID - int, not null, auto increment, primary
    ConfigurationKeyType - int, not null
    Key - varchar(50), not null
  
  StringConfigurationKeys
    ID - int, not null, primary (foreign key to ConfigurationKey.ID)
    StringValue - varchar(50), not null
  
  IntConfigurationKeys
    ID - int, not null, primary (foreign key to ConfigurationKey.ID)
    IntValue - int, not null
  </code></pre>
  
  <p>and the following classes structure:</p>
  
  <pre><code>public enum ConfigurationKeyType 
  {
      StringConfigurationKey = 0,
      IntConfigurationKey = 1
  }
  
  [Table("ConfigurationKeys")]
  public class ConfigurationKey
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int ID { get; set; }
  
      public ConfigurationKeyType ConfigurationKeyType { get; set; }
  
      public string Key { get; set; }
  }
  
  [Table("StringConfigurationKeys")]
  public class StringConfigurationKey : ConfigurationKey
  {
      public string StringValue { get; set; }
  }
  
  [Table("IntConfigurationKeys")]
  public class IntConfigurationKey : ConfigurationKey
  {
      public int IntValue { get; set; }
  }    
  </code></pre>
  
  <p>No other configurations and model builder mappings are made.   </p>
  
  <p>Now, when I do the following query:</p>
  
  <pre><code>var keys = context.ConfigurationKeys.ToArray();
  </code></pre>
  
  <p>Entity Framework returns an array of <strong>derived types</strong>.<br>
  I.e., <code>keys[0]</code> may be <code>IntConfigurationKey</code> and <code>keys[1]</code> may be of type <code>StringConfigurationKey</code>. I can safely cast it and access properties of derived types.<br>
  It is a great feature and I love it, but I would like to know how it works in order to maintain this functionality in future.<br>
  Does it use enum or does it look for an entity with the same ID across all tables?</p>