我只是停留在配置代码优先模型上。我正在实现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
{
...
}