gpt4 book ai didi

c# - EF TPH 继承查询

转载 作者:太空狗 更新时间:2023-10-29 20:18:26 27 4
gpt4 key购买 nike

尝试为我正在制作的系统实现一个非常简单的 TPH 设置,1 个基础类,2 个继承类。

但是继承的类都属于同一个实体集,所以在我的 ObjectContext using 循环中,我只能访问基本抽象类。我不太确定如何获得具体类的元素? (我也将其转换为使用 POCO)。

alt text

然后在我的应用程序中使用实体:

using (SolEntities sec = new SolEntities()) {
Planets = sec.CelestialBodies;
}

sec 上设置了一个 CelestialBodies 实体,但没有我预期的行星/卫星。

不太确定需要做什么才能访问它们。

谢谢

最佳答案

您可以使用OfType 方法:

using (SolEntities sec = new SolEntities()) {
Planets = sec.CelestialBodies.OfType<Planet>();
}

关于c# - EF TPH 继承查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4578598/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com