映射TPT在EF code首先4.1瓦特/不同的主键主键、不同、EF、TPT

2023-09-04 23:59:02 作者:安好.

我想在映射遗留数据库中的TPT继承层次(我不能改变列名)。所有的例子都具有相同名称的父母和子女表的主键。不幸的是,我的不行为这种方式。

I am trying to map a TPT inheritance hierarchy on a legacy database (I can't change column names). All of the examples have the primary keys of the parent and children tables with the same name. Unfortunately, mine doesn't behave this way.

作为简化实例

Vehicle
----------------
VehicleId
Make
Model
----------------

Car
----------------
CarId        
SomeOtherField
----------------

CarId和VehicleId实际上是相同的ID和是应使用的表相关联的值。是否有用于创建本作中,$ C $一个TPT关系C首先任何支持?

CarId and VehicleId are actually the same id and are the values that should be used to associate the tables. Is there any support for creating this as a TPT relationship in Code First?

推荐答案

这里是一个关于这个问题从EF组语句:

Here is a statement about this issue from the EF team:

不幸的是,这是不可能在这个阶段。我知道这是不是   一个伟大的答案,但其中一个方案是创建一个重命名视图   的PK / FK列,然后映射到。

Unfortunately this isn't possible at this stage. I realize this isn't a great answer but one option would be to create a view that renames the PK/FK column and then map to that.

这是一个从2011年2月因此它关系到EF code-一是早期CTP版。但我认为,这种情况下仍然不支持EF 4.1。

It's from February 2011. So it was related to an earlier CTP version of EF Code-First. But I believe that this scenario is still not supported in EF 4.1.

另外一个类似的问题在这里有不符合有关EF 4.1 code-的第一个结果:我如何使用TPT的继承模型时主键有不同的名字?

Also a similar question here with not satisfying result regarding EF 4.1 Code-First: How can I use TPT inheritance models when primary keys have different names?