Entity Framework 4: Inheritance (table per type) - Derived table has a composite PK
Is it possible to have "table per type" inheritance in the Entity Framework 4 if the derived table has a composite primary key?
Here is my table setup:
TABLE: ConfigurationKey (Base Entity)
PK: Id
T开发者_Go百科ABLE: ConfigurationKey_Device (Derived Entity)
PK: ConfigurationKeyId (FK to ConfigurationKey.Id)
PK: DeviceId (FK to Device.Id)
For what it's worth, ConfigurationKey is going to be abstract and other types are going to derive from ConfigurationKey.
Using the EF designer, I have:
- Added the inheritance rule
- Deleted ConfigurationKeyId from ConfigurationKey_Device
- Deleted the FK linking ConfigurationKey_Device to ConfigurationKey
- Updated the mapping of the ConfigurationKey_Device.ConfigurationKeyId column to the inherited Id property.
The error I am now getting is:
Error 3003: Problem in mapping fragments starting at line xxx:All the key properties (ConfigurationKeys.Id) of the EntitySet ConfigurationKeys must be mapped to all the key properties (ConfigurationKey_Device.ConfigurationKeyId, ConfigurationKey_Device.DeviceId) of table ConfigurationKey_Device.
Thanks, Chris
The error message answers to your question itself.
You are actually trying to inherit from an entity with one-column key with an entity with two-column key.
It seems the better solution will be either to have a ComplexType enclosing the common set of properties, or a common interface implementing the necessary functionality.
精彩评论