我有以下课程:
public class Entity
{
public long Id {get;set;}
}
public abstract class Base
{
public long Id {get;set;}
public abstract ICollection<Entity> Entities {get;set;}
}
public class Child : Base
{
public override ICollection<Entity> Entities {get;set;}
}
映射:
modelBuilder.Entity<Child>().Map(
m => {
m.ToTable("Children");
m.MapInheritedProperties();
});
modelBuilder.Entity<Child>().HasMany(m => m.Entities).WithMany();
我得到以下异常:
The navigation property 'Entities' is not a declared property on type
'EventCriteria'. Verify that it has not been explicitly excluded from the model
and that it is a valid navigation property.
我做错了什么?
答案 0 :(得分:0)
您正在映射TPC继承(您调用MapInheritedProperties
),在这种情况下,Entities
集合必须映射到Base
实体,而不是Child
实体。