How to map table type inheritance to type (TPT) in Entity Designer?

I have created a large number of tables in my database, here are some of them:

Table Name -Item ItemID - PK (Auto Increment) Title Table Name -Game ItemID - PK Console Table Name -Film ItemID - PK Type 

I also added a link between ItemID Item and Film-Item and Game-Item

The problem is when I put this in Visual Studio and use the Entity Framework, it breaks down the classes and completely removes the movie and the game ... I then can not use the game or movie as an entity in my ASP code, any idea how to solve it?

+6
entity-framework
source share
1 answer

Yes, that’s how Entity Designer works. If you model your structure in the database and use the update model from the database, it will really be modeled, since the general beacuse EF associations do not yet know that you want to model it as inheritance. You will receive the following:

enter image description here

You must manually modify this model to use TPT inheritance. Delete both relationships first. It will also remove the navigation properties and you will get the following:

enter image description here

Use Inheritance from the toolbar (as described in the previous screenshot) and draw a line from Film to Item and from Game to Item . Now you need to finish this model. The current model will not be validated because the ItemId displayed in both the parent and the child. Remove ItemId from the Film and Game objects. You can also create an Item Abstract object, and you get the following:

enter image description here

+4
source share

All Articles