实体框架6继承导航

时间:2019-08-19 02:57:01

标签: c# entity-framework ef-fluent-api

我只是停留在配置代码优先模型上。我正在实现TPT继承,但是我想在导航中使用具体的类来保护在Foo中添加到集合或设置为Bar的内容。怎么做?还是我应该总是创建OfType呼叫?

public abstract class Foo
{
    ...
    public Guid BarId { get; set; }
    public virtual Bar Bar { get; set; }
}

public class ConcreteFooFirst : Foo
{
    ...
}

public class ConcreteFooSecond : Foo
{
    ...
}

public abstract class Bar
{
    ...
    public virtual ICollection<Foo> Foos { get; private set; } = new HashSet<Foo>();
}

public class ConcreteBarFirst : Bar
{
    ...
}

public class ConcreteBarSecond : Bar
{
    ...
}

0 个答案:

没有答案