在子类中设置discriminator属性 - Entity Framework

时间:2017-04-09 22:30:11

标签: c# entity-framework inheritance tph ef-model-builder

我有以下问题。我用Entity Framework构建TPH继承,我需要在子类的现有属性上设置discriminator列。示例:

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继承的标识符。我怎样才能做到这一点?

0 个答案:

没有答案