映射TPT在EF代码首先4.1 w /不同的主键 [英] Mapping TPT in EF Code First 4.1 w/ Different Primary Keys

查看:88
本文介绍了映射TPT在EF代码首先4.1 w /不同的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在遗留数据库上映射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,并且是用于关联表的值。有没有支持在Code First中创建一个TPT关系?

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:


不幸的是,这在现阶段是不可能的。我意识到这不是
a伟大的答案,但一个选择是创建一个视图,重命名
的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月开始的。因此,它与早期的C Code版本的EF Code-First有关。但是我相信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-First的结果:当主键有不同的名称时,如何使用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?

这篇关于映射TPT在EF代码首先4.1 w /不同的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆