NotSupportedException: type A cannot be displayed as definede. Concrete Table (TPC) EF6

I have a 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 configuration 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 we get:

System.NotSupportedException: The type "ItemCat" cannot be displayed as defined because it displays inherited properties from types that use object separation or another form of inheritance. Either select a different inheritance mapping strategy to not display the inherited properties, or change all types in the hierarchy to display the inherited properties and not use separation

Update: I am also reading this

0
source share
1 answer

Find the answer. just delete the Map in the ItemCatConfig class.

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

In abstract classes, TPC is not implemented in db. ItemCat inherits from abstract classes and does not need map configuration explicitly.

0
source

Source: https://habr.com/ru/post/970193/


All Articles