【问题标题】:Not retrieving data from Table per concrete type不按具体类型从表中检索数据
【发布时间】:2026-01-12 09:50:01
【问题描述】:

我已经在实体框架中实现了 Table Per Concrete Type 如下

我有 Vehicle 和 OldVehicle 表。 Vehicle 是基础实体,OldVehicle 是派生实体。

我已从派生实体(即 OldVehicle)中删除了所有重叠属性。

现在我尝试从 OldVehicle 中检索数据,如下所示:

CarRentalModelEntities context = new CarRentalModelEntities();
var oldVeh = context.Vehicles.OfType<OldVehicle>();
foreach (var oh in oldVeh)
{
    --Some Code Here--                   
}

我的 OldVehicle 表中有 9 条记录。

【问题讨论】:

  • 问题出在哪里?
  • 不确定。我没有收到任何错误消息。
  • 请显示映射。

标签: c# entity-framework inheritance


【解决方案1】:

我忘记在 XMl 中添加 OldVehicles 的一些属性。现在我得到了结果。

感谢 Gert Arnold 询问有关映射的问题。

【讨论】: