NotSupportedException: The type A cannot be mapped as definede. Table per Concrete (TPC) EF6
Asked Answered
B

1

0

I have model like:

public abstract class Entity   
 {    
    public int Id { get; set; }  
  }

public abstract  class Tree : Entity
    {
        public Tree() { Childs = new List<Tree>(); }

        public int? ParentId { get; set; }

        public string Name { get; set; }

        [ForeignKey("ParentId")]
        public ICollection<Tree> Childs { get; set; }

    }

 public  abstract class Cat : Tree
    {

        public string ImageUrl { get; set; }

        public string Description { get; set; }

        public int OrderId { get; set; }

    }

  public class ItemCat : Cat
        {
            ...
            public virtual ICollection<Item> Items { get; set; }
        }

and config classes:

public class CatConfig : EntityTypeConfiguration<Cat>
    {
        public CatConfig()
        {
            //properties
            Property(rs => rs.Name).IsUnicode();
            Property(rs => rs.ImageUrl).IsUnicode();
            Property(rs => rs.Description).IsUnicode();
        }
    }

 public class ItemCatConfig :EntityTypeConfiguration<ItemCat>
    {
        public ItemCatConfig()
        {

            Map(m => { m.ToTable("ItemCats"); m.MapInheritedProperties(); });
        }
    }

and DbContext:

public class Db :  IdentityDbContext<MehaUser>
    {
        public Db():base("Db")
        {
        }

        public DbSet<ItemCat> ItemCats { get; set; }
    }
 protected override void OnModelCreating(DbModelBuilder mb)
        {
            mb.Configurations.Add(new ItemCatConfig());

            base.OnModelCreating(mb);
        }

but get:

System.NotSupportedException: The type 'ItemCat' cannot be mapped as defined because it maps inherited properties from types that use entity splitting or another form of inheritance. Either choose a different inheritance mapping strategy so as to not map inherited properties, or change all types in the hierarchy to map inherited properties and to not use splitting

Update: I also Read this

Bala answered 10/4, 2014 at 9:16 Comment(0)
B
0

Find the answer. just remove Map in ItemCatConfig Class.

 Map(m => { m.ToTable("ItemCats"); m.MapInheritedProperties(); });

In TPC abstract classes does not implement in db. ItemCat inherit from abstract classes and it doesn't need to Map configuration explicitly.

Bala answered 10/4, 2014 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.