C# 在EF模型实体的层次结构中添加中间基类

C# 在EF模型实体的层次结构中添加中间基类,c#,entity-framework,odata,C#,Entity Framework,Odata,我有一个模型,其中有两个继承级别和两个表,更不像这样: public abstract class A { public string FooA { get; set; } } public class B : A { public string FooB { get; set; } } public class DX : B { public string FooC { get; set; } public string FooDX { get; set;

我有一个模型,其中有两个继承级别和两个表,更不像这样:

public abstract class A
{
    public string FooA { get; set; }
}

public class B : A
{
    public string FooB { get; set; }
}

public class DX : B
{
    public string FooC { get; set; }
    public string FooDX { get; set; }
}

public class DY : B
{
    public string FooC { get; set; }
    public string FooDY { get; set; }
}

modelBuilder.Entity<B>().ToTable("B", SchemaName);   // B table has columns FooA and FooB
modelBuilder.Entity<DX>().ToTable("DX", SchemaName); // DX table has columns FooC and FooDX
modelBuilder.Entity<DY>().ToTable("DY", SchemaName); // DY table has columns FooC and FooDY
public abstract class C : B
{
    public string FooC { get; set; }
}

public class DX : B
{
    public string FooDX { get; set; }
}

public class DY : B
{
    public string FooDY { get; set; }
}
我不能修改数据库,但是有一个DX和DY的公共类会让我的生活更轻松。但是,当我尝试此操作时,会出现以下错误:

列名“鉴别器”无效。列名“FooC”无效

“鉴别器”部分使我认为实体框架试图从“B”表而不是“DX”和“DY”表中查询“C”

在不修改数据库和保持三级继承的情况下,是否有解决此问题的方法

更新:我觉得应该使用来解决这个问题,所以我制作了
抽象的
我不想映射到表的类,并将我的模型更新为:

modelBuilder.Entity<B>().Map(m =>
{
    m.MapInheritedProperties();
    m.ToTable("B", SchemaName);
});

modelBuilder.Entity<DX>().Map(m =>
{
    m.MapInheritedProperties();
    m.ToTable("DX", SchemaName);
});

modelBuilder.Entity<DY>().Map(m =>
{
    m.MapInheritedProperties();
    m.ToTable("DY", SchemaName);
});
modelBuilder.Entity().Map(m=>
{
m、 MapInheritedProperties();
m、 ToTable(“B”,SchemaName);
});
modelBuilder.Entity().Map(m=>
{
m、 MapInheritedProperties();
m、 ToTable(“DX”,SchemaName);
});
modelBuilder.Entity().Map(m=>
{
m、 MapInheritedProperties();
m、 ToTable(“DY”,SchemaName);
});
但是我得到了以下错误:

“无法按定义映射类型“DY”,因为它映射使用实体拆分或其他继承形式的类型的继承属性。选择不同的继承映射策略以不映射继承的属性,或者将层次结构中的所有类型更改为映射继承的属性而不使用拆分。"