Tuesday, December 10, 2013

Inheritance Strategy in Code-First

In the code first approach, database schema will be created based on the design of your domain classes. You may design your domain classes in object-oriented way where you can use inheritance and polymorphism. Object-oriented systems model has “has a” and “is a” relationships where as SQL based relational model has only “has a” relationships. So how would you map object-oriented with relational database?

There are three different approaches to represent an inheritance hierarchy:

  • Table per Hierarchy (TPH): This approach suggests one table for entire class inheritance hierarchy. Table includes discriminator column which distinguish between inheritance classes.

  • Table per Type (TPT): This approach suggests one table for each classes thus each class will have its persistence table.

  • Table per Concrete class (TPC): This approach suggests one table for one concrete class but not for abstract class. So if you inherit abstract class in multiple concrete classes then properties of abstract class will be part of each table of concrete class.
We are not going into detail here. Visit following reference link to understand it in detail:



No comments:

Post a Comment