none
Error 3032: Problem in mapping fragments : mapped to the same rows in table RRS feed

  • Question

  • The following is my class hierarchy:

    Document (abstract class)		
    ├ RES
    ├ RFQ
    └ MutlipleBudgetDocument (abstract class)
    └ POBase (abstract class)
    ├ EPO
    └ CPO 

    The following are my database tables:

     

    Document (table with a DocumentType Discriminator column)		
    ├ RES (TPT)
    ├ RFQ (TPT)
    └ MutlipleBudgetDocument (TPH)
    └ POBase (table with a POType Discriminator column)
    ├ EPO (TPH)
    └ CPO (TPH)

     

    When using the context, I get the "Error 3032: Problem in mapping fragments : mapped to the same rows in table" error.

    Anyone has any idea why?

     

     

     

     

    Friday, August 19, 2011 10:17 AM

Answers

  • Hi swirl,

    Welcome!

    I will show you a sample about TPH:

     public class Parent
      {
        public int ID { get; set; }
        public int Owner_Id { get; set; }
        public Owner Owner { get; set; }
      }
      public class Child1:Parent
      {
        
      }
      public class Child2:Parent
      {
        
      }
      public class Owner
      {
        public int ID { get; set; }
        public ICollection<Parent> ParentItems
        { get; set; }
      }
      public class MyContext:DbContext
      {
        public DbSet<Parent> Parents { get; set; }
        public DbSet<Owner> Owners { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
          modelBuilder.Entity<Parent>().Property(p => p.Owner_Id).HasColumnName("OwnerId");
          modelBuilder.Entity<Parent>().HasRequired(p => p.Owner).WithMany(o => o.ParentItems).HasForeignKey(p => p.Owner_Id);     
          modelBuilder.Entity<Parent>().Map<Child1>(mc => { mc.Requires("disc").HasValue("Child1"); }).Map<Child2>(mc => { mc.Requires("disc").HasValue("Child2"); });
        }
      }
    
    

    The 'disc' property doesn't existed in Parent class. I think your problem may relate it.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Saturday, August 20, 2011 4:46 AM
    Moderator

All replies

  • Hi swirl,

    Welcome!

    I will show you a sample about TPH:

     public class Parent
      {
        public int ID { get; set; }
        public int Owner_Id { get; set; }
        public Owner Owner { get; set; }
      }
      public class Child1:Parent
      {
        
      }
      public class Child2:Parent
      {
        
      }
      public class Owner
      {
        public int ID { get; set; }
        public ICollection<Parent> ParentItems
        { get; set; }
      }
      public class MyContext:DbContext
      {
        public DbSet<Parent> Parents { get; set; }
        public DbSet<Owner> Owners { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
          modelBuilder.Entity<Parent>().Property(p => p.Owner_Id).HasColumnName("OwnerId");
          modelBuilder.Entity<Parent>().HasRequired(p => p.Owner).WithMany(o => o.ParentItems).HasForeignKey(p => p.Owner_Id);     
          modelBuilder.Entity<Parent>().Map<Child1>(mc => { mc.Requires("disc").HasValue("Child1"); }).Map<Child2>(mc => { mc.Requires("disc").HasValue("Child2"); });
        }
      }
    
    

    The 'disc' property doesn't existed in Parent class. I think your problem may relate it.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Saturday, August 20, 2011 4:46 AM
    Moderator
  • Hi,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 26, 2011 3:20 AM
    Moderator