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() {
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
source share