实体框架4:继承(每种类型的表) - 派生表具有复合PK

时间:2010-10-01 07:38:04

标签: .net entity-framework inheritance

如果派生表具有复合主键,是否可以在Entity Framework 4中具有“每类型表”继承?

这是我的表格设置:

TABLE: ConfigurationKey (Base Entity)
PK: Id

TABLE: ConfigurationKey_Device (Derived Entity)
PK: ConfigurationKeyId (FK to ConfigurationKey.Id)
PK: DeviceId (FK to Device.Id)

对于它的价值,ConfigurationKey将是抽象的,其他类型将从ConfigurationKey派生。

使用EF设计师,我有:

  • 添加了继承规则
  • 从ConfigurationKey_Device
  • 删除了ConfigurationKeyId
  • 删除了将ConfigurationKey_Device链接到ConfigurationKey的FK
  • 更新了ConfigurationKey_Device.ConfigurationKeyId列到继承的Id属性的映射。

我现在得到的错误是:

  

错误3003:映射问题   从xxx行开始的片段:全部   关键属性(ConfigurationKeys.Id)   EntitySet ConfigurationKeys   必须映射到所有密钥   性能   (ConfigurationKey_Device.ConfigurationKeyId,   ConfigurationKey_Device.DeviceId)   表ConfigurationKey_Device。

谢谢, 克里斯

1 个答案:

答案 0 :(得分:0)

错误消息会回答您的问题本身 您实际上是尝试从具有单列密钥的实体继承具有双列密钥的实体 似乎更好的解决方案是将ComplexType包含在公共属性集中,或者是实现必要功能的公共接口。

相关问题