title: Mapping inheritance hierarchy in EF 4.3.1 code-first always fails using Map method
body: <p>Simple test project working from examples in Julia Lerman's EF Code First book. Not a single example works TPH, TPT or TPC when using the Map method, but fine without. Every other aspect of EF (I have a part developed application) appears to work okay. I'm using VS 2010/.NET 4 with all latest updates and I even resorted to repairing the VS installation today.</p>
  
  <p>The following TPH example throws an InvalidOperationException - "Map was called more than once for type 'Child' and at least one of the calls didn't specify the target table name."</p>
  
  <pre><code>using System.Linq;
  using System.Data.Entity;
  
  namespace ConsoleApplication1
  {
      public class Program
      {
          static void Main(string[] args)
          {
              Database.SetInitializer(new DropCreateDatabaseIfModelChanges&lt;Context&gt;());
              var children = new Context().Set&lt;Child&gt;().ToList();
          }
      }
  
      public class Parent
      {
          public int Id { get; set; }
          public string Name { get; set; }
      }
  
      public class Child : Parent
      {
      }
  
      public class Context : DbContext
      {
          DbSet&lt;Parent&gt; Parents { get; set; }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              modelBuilder.Entity&lt;Parent&gt;()
                  .Map(m =&gt;
                      {
                          m.Requires("EntityType").HasValue("Parent");
                          m.ToTable("Families");
                      })
              .Map&lt;Child&gt;(m =&gt; m.Requires("EntityType").HasValue("Child"));
          }
      }
  }
  </code></pre>
  
  <p>Another example, TPT this time, throws "The type 'Child' has already been mapped to table 'Children'. Specify all mapping aspects of a table in a single Map call."</p>
  
  <pre><code>        protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              modelBuilder.Entity&lt;Parent&gt;()
                  .Map(m =&gt; m.ToTable("Families"))
                  .Map&lt;Child&gt;(m =&gt; m.ToTable("Children"));
          }
  </code></pre>
  
  <p>The final example, TPC, throws similar "The type 'Child' has already been mapped to table 'Children'. Specify all mapping aspects of a table in a single Map call."</p>
  
  <pre><code>        protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              modelBuilder.Entity&lt;Parent&gt;()
                  .Map(m =&gt; m.ToTable("Families"))
                  .Map&lt;Child&gt;(m =&gt;
                      {
                          m.ToTable("Children");
                          m.MapInheritedProperties();
                      });
          }
  </code></pre>
  
  <p>I've tried any number of other examples too with similar results. Either I'm missing something very basic or I suspect I have an installation/configuration problem. My PC also has VS2008 installed and a few months ago I did a lot of re-configuring SQL Server as I had 4 different versions installed. I'm now using 2008 R2 Express.</p>
  
  <p>Has anybody seen similar or have any idea how I can trace/debug what's going on in EF?</p>