0

我有以下问题。我正在使用实体框架构建 TPH 继承,我需要在子类的现有属性上设置鉴别器列。例子:

public abstract class Building 
{
    //... some properties
    public BuildingType BType { get; set; } // sub class with discriminator property
}

public class BuildingA : Building
{

}

public class BuildingB : Building
{

}

public class BuildingType
{
    //... some properties
    public string Category { get; set; } 
    /*
    discriminator property
    if this property is set to "A" then the building is type BuildingA
    and if is set to "B" then the building is type BuildingB
    */
}

所以 - 每个建筑物都需要 BuildingType 属性,而 BuildingType 类具有属性 Category(已经存在)并且可以区分建筑物 TPH 继承。我怎样才能做到这一点?

4

0 回答 0