Search code examples
c#entity-frameworkentity-framework-4table-per-type

How to setup table per type inhertiance in entity framework when the derived table uses its own primary key?


Suppose I have a table structure such as:

Order    
  ID int, primary key 
  Name, string
  OtherOrderFields...

RetailOrder
  ID int, primary key
  OrderID, foreign key
  RetailOrderFields...

In entity framework 4, is it possible to set up table per type inheritance so that RetailOrder derives from Order? All the examples I've seen so far have the derived class using the foreign key (OrderID in this example) as the primary key for the table, but what if that's not the case and each table maintains its own primary key?


Solution

  • No, it's impossible. I think, your database schema guess aggregation (1-1 relation) instead of inheritance.