views:

50

answers:

1

Hi there,

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

TABLE: 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

A: 

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.

Devart
Yes, what I was trying to do didn't make sense. What I thought should be a derived entity was actually more like a joining table. Thanks for your feedback.
da_ponc