title: EF 4.1 Code First problem with parent child and Inheritance Mapping
body: <p>I have run into some problems with Inheritance Mapping, I can't get it to map correct to the base class, and get an <em>Invalid column</em> on all the fields in the base class (Elements) </p>
  
  <p>The project wos working before we upgraded from CTP5 to 4.1 and where using the .IsIndependent()</p>
  
  <p>My code look like this:</p>
  
  <p>Table structure:</p>
  
  <pre><code>CREATE TABLE [dbo].[elements](
      [elementID] [uniqueidentifier] NOT NULL,
      [elementElementID] [uniqueidentifier] NULL,
      [name] [nvarchar](50) NOT NULL,
      [solutionID] [int] NOT NULL,
      [elementTypeID] [int] NOT NULL,
      [dateCreate] [datetime] NOT NULL,
      [dateChange] [datetime] NOT NULL,
      [placeholderNumber] [int] NULL
  )
  
  CREATE TABLE [dbo].[elementRoots](
      [elementID] [uniqueidentifier] NOT NULL,
      [allowsiteCounts] [int] NOT NULL
  )
  
  
  CREATE TABLE [dbo].[elementSites](
      [elementID] [uniqueidentifier] NOT NULL,
      [languageCode] [nvarchar](5) NOT NULL
  )
  
  
  CREATE TABLE [dbo].[elementPages](
      [elementID] [uniqueidentifier] NOT NULL,
      [elementMasterID] [uniqueidentifier] NULL,
      [title] [nvarchar](50) NOT NULL,
      [desciption] [nvarchar](255) NULL,
      [path] [nvarchar](512) NULL,
  )
  </code></pre>
  
  <p>Mapping;</p>
  
  <pre><code>public DbSet&lt;Element&gt; Elements { get; set; }
  public DbSet&lt;ElementRoot&gt; ElementRoots { get; set; }
  public DbSet&lt;ElementSite&gt; ElementSites { get; set; }
  public DbSet&lt;ElementPage&gt; ElementPages { get; set; }
  
  protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
  
  
      modelBuilder.Entity&lt;Element&gt;().HasKey(x =&gt; x.elementId);
  
      modelBuilder.Entity&lt;Element&gt;()
          .HasOptional(s =&gt; s.Parent)
          .WithMany(c =&gt; c.Children)
          .HasForeignKey(s =&gt; s.elementElementId);
  
          modelBuilder.Entity&lt;Element&gt;().ToTable("elements");
  
      modelBuilder.Entity&lt;ElementRoot&gt;().Map(m =&gt;
      {
  
          m.MapInheritedProperties();
          m.ToTable("elementRoots");
  
      });
  
      modelBuilder.Entity&lt;ElementSite&gt;().Map(m =&gt;
      {
          m.MapInheritedProperties();
          m.ToTable("elementSites");
  
      });
  
      modelBuilder.Entity&lt;ElementPage&gt;().Map(m =&gt;
      {
          m.MapInheritedProperties();
          m.ToTable("elementPages");
      });
  }
  </code></pre>
  
  <p>Error message i recive:</p>
  
  <pre><code>Invalid column name 'solutionID'.
  Invalid column name 'name'.
  Invalid column name 'solutionID'.
  Invalid column name 'elementTypeID'.
  Invalid column name 'dateCreate'.
  Invalid column name 'dateChange'.
  Invalid column name 'elementElementId'.
  Invalid column name 'placeholderNumber'.
  Invalid column name 'solutionID'.
  Invalid column name 'name'.
  Invalid column name 'solutionID'.
  Invalid column name 'elementTypeID'.
  Invalid column name 'dateCreate'.
  Invalid column name 'dateChange'.
  Invalid column name 'elementElementId'.
  Invalid column name 'placeholderNumber'.
  Invalid column name 'solutionID'.
  Invalid column name 'name'.
  Invalid column name 'solutionID'.
  Invalid column name 'elementTypeID'.
  Invalid column name 'dateCreate'.
  Invalid column name 'dateChange'.
  Invalid column name 'elementElementId'.
  Invalid column name 'placeholderNumber'.]
     System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2030802
     System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584
     System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
     System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
     System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
     System.Data.SqlClient.SqlDataReader.get_MetaData() +86
     System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +311
     System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987
     System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
     System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
     System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
     System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
     System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +10
     System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +443
  </code></pre>