Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7578643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:28:57+00:00 2026-05-30T17:28:57+00:00

I’m using Entity Framework 4.3 with code first and manual migrations. I’m trying to

  • 0

I’m using Entity Framework 4.3 with code first and manual migrations. I’m trying to map a TPH (table-per-hierarchy) setup which uses two custom discriminator fields. One for the discriminator itself and the other for soft deletes (much like the “where” option in NH class mappings). The exact same setup works just fine in another project which runs on EF 4.2.

I get the error when trying to add a migration using the “add-migration” command in the NuGet console. I have tried all combinations of defining the table name – attributes on class, in “OnModelCreating” method, in EntityTypeConfiguration classes etc. My previous migrations which didn’t involve complex hierarchy mappings have worked just fine.

Is there some breaking change in EF 4.3 that I’ve stumbled upon?

The code:

//---- Domain classes ---------------------

public abstract class ParentClass
{
    public string ParentString { get; set; }
}

public class Foo : ParentClass
{
    public string FooString { get; set; }
}

public class Bar : ParentClass
{
    public string BarString { get; set; }
}

//---- Mapping configuration --------------

public class ParentConfiguration : EntityTypeConfiguration<ParentClass>
{
    public ParentConfiguration()
    {
        Map<Foo>(m =>
        {
            m.Requires("IsActive").HasValue(1);
            m.Requires("Type").HasValue("Foo");
        })
        .ToTable("Parent");

        Map<Bar>(m =>
        {
            m.Requires("IsActive").HasValue(1);
            m.Requires("Type").HasValue("Bar");
        })
        .ToTable("Parent");
    }
}

//---- Context ----------------------------

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Configurations.Add(new ParentConfiguration());
}

The error:

System.InvalidOperationException: The type 'Foo' has already been mapped to table 'Parent'. Specify all mapping aspects of a table in a single Map call.
   at System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.AddMappingConfiguration(EntityMappingConfiguration mappingConfiguration)
   at System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ReassignSubtypeMappings()
   at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(Action`1 writeXml)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(DbContext context)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
   at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()

Mihkel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:28:58+00:00Added an answer on May 30, 2026 at 5:28 pm

    This is a known issue with 4.3 and 4.3.1. (We found it too late to put the fix in 4.3.1.) Luckily there is a fairly simple way to change your code that should make it work.

    In a nutshell, you used to be able to make chained map calls on a single EntityConfiguration in 4.1. and 4.2. Something like this pattern:

    modelBuilder.Entity<Parent>()
        .Map<Foo>(...)
        .Map<Bar>(...);
    

    This doesn’t work in 4.3 and instead you have to make each Map call on an EntityConfiguration for that entity. So a pattern something like this:

    modelBuilder.Entity<Foo>()
       .Map<Foo>(...);
    
    modelBuilder.Entity<Bar>()
       .Map<Bar>(...);
    

    Taking your case specifically, this should work:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ParentClass>()
            .ToTable("Parent");
    
        modelBuilder.Entity<Foo>()
            .Map(m =>
                    {
                        m.Requires("IsActive").HasValue(1);
                        m.Requires("Type").HasValue("Foo");
                    });
    
        modelBuilder.Entity<Bar>()
            .Map(m =>
                    {
                        m.Requires("IsActive").HasValue(1);
                        m.Requires("Type").HasValue("Bar");
                    });
    }
    

    (I’ve removed a few of the generic parameters since they aren’t needed, but that’s not important.)

    Doing this using explicit EntityConfigurations you would use something like this:

    public class ParentConfiguration : EntityTypeConfiguration<ParentClass>
    {
        public ParentConfiguration()
        {
            ToTable("Parent");
        }
    }
    
    public class FooConfiguration : EntityTypeConfiguration<Foo>
    {
        public FooConfiguration()
        {
            Map(m =>
            {
                m.Requires("IsActive").HasValue(1);
                m.Requires("Type").HasValue("Foo");
            });
        }
    }
    
    public class BarConfiguration : EntityTypeConfiguration<Bar>
    {
        public BarConfiguration()
        {
            Map(m =>
            {
                m.Requires("IsActive").HasValue(1);
                m.Requires("Type").HasValue("Bar");
            });
        }
    }
    

    And then

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations
            .Add(new ParentConfiguration())
            .Add(new FooConfiguration())
            .Add(new BarConfiguration());
    }
    

    We plan to fix this in 5.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.