Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate table per hierarchy using entity framework 5 model first

I'm using Visual Studio 2012 with entity Framework 5 model first. I would like to generate my database using a table per hierarchy strategy, but can't find that option. The Entity Designer Database Generation Power Pack is not available for visual studio 2012, or I can't find it.

Anyone a suggestion?

like image 617
Wim Simons Avatar asked Nov 12 '22 14:11

Wim Simons


1 Answers

Table Per Hierarchy or commonly known by (TPH) describes mapping inherited types to a single database table (a model entity in your case) that uses a discriminator column to differentiate one subtype from another. When you create inheritance in your model, this is how Code First convention will infer the table mapping by default.

You can accomplish this approach by doing for example

in visual studio .edmx editor, right click on the surface, use the Add –> Entity

Example

i added two entities student and professor that the base type is going to be person, after that you should have something like this

Model

With this you can create the Table per hierarchy model.

like image 168
Overmachine Avatar answered Dec 10 '22 09:12

Overmachine