0

I have these three models:

public class Equipment
{
    public int ID { get; set; }
    public string title { get; set; }

}

[Table("Vessels")]
public class Vessel:Equipment
{
    public string Size { get; set; }

}

[Table("Tubes")]
public class Tube : Equipment
{
    public string Pressure{ get; set; }

}

I want to show a list of Equipments with 2 columns title and type.

for example:

Title        Type
------       -------
101-1        vessel
101-2        vessel
102-3        tube

I don't know how to make a discriminator column in Equipments to show the type of each equipments.

EDITED

If I have a discriminator in Equipment entity like:

public class Equipment
{
    public int ID { get; set; }
    public string title { get; set; }
    public string type{ get; set; }  //as discriminator
}

I can get the query in controller or repository like this:

var equipments=from e in db.Equipments
               select e;
4

1 回答 1

1

您不能根据 EF 映射创建鉴别器列 - TPT 继承不支持它,因为鉴别器是一个子表。您可以尝试使用类似的东西:

public abstract class Equipment
{
    public int ID { get; set; }
    public string title { get; set; }

    [NotMapped]
    public abstract string Type { get; }
}  

并覆盖Type子类型中的属性以获得正确的名称。您将无法在 Linq-to-Entities 查询中使用该属性,因为它没有被映射。

于 2013-01-13T12:18:11.987 回答