title: Entity Framework Code First Many-to-Many relationship and inheritance
body: <p>Forgive me if this question has been answered somewhere, I have been having a hard time finding a solution for this problem. </p>
  
  <p>I am trying to set up EF Code First on an MVC4 Project. I have a User and Customer that both inherit from Person. I then have a Template object that has a Many-to-Many relationship with Customer and a One-to-Many relationship with User. Here is how I have it set up:</p>
  
  <p><strong>MODELS</strong></p>
  
  <pre><code>public class Person
  {
      [Key]
      public int PersonID { get; set; }
  
      public string LastName { get; set; }
      public string FirstName { get; set; }
  
      public string FullName
      {
          get
          {
              return String.Format("{0} {1}", FirstName, LastName);
          }
      }
  
      public string Email { get; set; }
  
      public virtual List&lt;Template&gt; Templates { get; set; }
  }
  
  public class User : Person
  {
      .... 
  }
  
  public class Customer : Person
  {
      ....
  }
  
  public class Template
  {
      public int TemplateId { get; set; }
      public string TemplateName { get; set; }
  
      public virtual List&lt;Customer&gt; Customers { get; set; }
  
      [ForeignKey("User")]
      public int UserId { get; set; }
      public virtual User User { get; set; }
  }
  </code></pre>
  
  <p><strong>CONTEXT</strong></p>
  
  <pre><code>public class ProjectContext : DbContext
  {
      public ProjectContext()
          : base("name=ProjectDB")
      {
      }
  
      public DbSet&lt;Template&gt; Templates { get; set; }
      public DbSet&lt;User&gt; Users { get; set; }
      public DbSet&lt;Customer&gt; Customers { get; set; }
      public DbSet&lt;Person&gt; People { get; set; }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Conventions
              .Remove&lt;PluralizingTableNameConvention&gt;();
  
          modelBuilder.Entity&lt;Template&gt;()
              .HasMany(x =&gt; x.Customers)
              .WithMany(x =&gt; x.Templates)
              .Map(x =&gt; x.MapLeftKey("TemplateId")
                  .MapRightKey("PersonId")
                  .ToTable("TemplateCustomer")
              );
      }
  }
  </code></pre>
  
  <p>If I remove the Person DBSet out of the context this works fine but sets up TPT inheritance. I would like to use TPH inheritance, but when I enable migrations with the Person DBSet in the context it chokes:</p>
  
  <p>NavigationProperty 'Templates' is not valid. Type 'MvcProject.Models.Customer' of FromRole 'Template_Customers_Target' in AssociationType 'MvcProject.Models.Template_Customers' must exactly match with the type 'MvcProject.Models.Person' on which this NavigationProperty is declared on.</p>
  
  <p>Where am I going wrong here?</p>