Entity framework 在EntityTypeConfiguration中未忽略属性?

Entity framework 在EntityTypeConfiguration中未忽略属性?,entity-framework,entity-framework-core,ef-core-3.1,Entity Framework,Entity Framework Core,Ef Core 3.1,我有一个简单的实体类,其中包含基类列表,在模型中被忽略: public class MyClass { public int Id {get;set;} public List<BaseChild> BaseChildren {get; set;} } 但出于某种原因,我一直得到以下例外: 无法在“实例”上配置密钥,因为它是派生类型。必须在根类型“BaseChild”上配置密钥。如果您不希望“BaseChild”包含在模型中,请确保它未包含在您上下文中的DbSet

我有一个简单的实体类,其中包含基类列表,在模型中被忽略:

public class MyClass
{
    public int Id {get;set;}
    public List<BaseChild> BaseChildren {get; set;}
}

但出于某种原因,我一直得到以下例外:

无法在“实例”上配置密钥,因为它是派生类型。必须在根类型“BaseChild”上配置密钥。如果您不希望“BaseChild”包含在模型中,请确保它未包含在您上下文中的DbSet属性中,未在对ModelBuilder的配置调用中引用,也未从模型中包含的类型的导航属性中引用


builder.HasOne().WithOne()
。。即使忽略了BaseChild的MyClass集合,这仍然应该是
builder.HasOne().WithMany()
,尽管我不确定为什么要忽略BaseChildren。。。虽然不确定,但是BaseChild可能仍然需要对MyClass的引用。即使有很多错误,仍然会发生。
public class MyClassConfiguration : IEntityTypeConfiguration<MyClass>
{
    public void Configure(EntityTypeBuilder<MyClass> builder)
    {
        builder.Property(o => o.Id).UseHiLo();
        builder.HasKey(o => o.Id);
    
        builder.Ignore(o => o.BaseChildren);
    }
}
public abstract class BaseChild
{
    public int MyClassId { get; set; }
}

public abstract class BaseChildConfiguration<T> : IEntityTypeConfiguration<T> where T : BaseChild
{
    public virtual void Configure(EntityTypeBuilder<T> builder)
    {
        builder.HasKey(o => o.MyClassId);
        builder.HasOne<MyClass>()
            .WithOne()
            .HasForeignKey<T>(o => o.MyClassId);
    }
}

public class Instance : Component
{
    public long Code { get; set; }
}

public class InstanceConfiguration : BaseChildConfiguration<Instance>
{
}

protected override void OnModelCreating(ModelBuilder mb)
{
    mb.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}