How to map Table per Type (TPT) inheritance in Entity designer?

前端 未结 1 2040
野的像风
野的像风 2020-12-01 22:12

I have created a good amount of tables in my database, here are the problem ones:

Table Name -Item
    ItemID - PK (Auto Increment)
    Title        

Table          


        
相关标签:
1条回答
  • 2020-12-01 22:57

    Yes that is how Entity designer behaves. If you model your structure in the database and use Update model from database it will indeed be modeled as common associations beacuse EF doesn't know yet that you want to model it as inheritance. You will get this:

    enter image description here

    You must manually modify this model to use TPT inheritance. First delete both relations. It will also remove navigation properties and you will get this:

    enter image description here

    Use Inheritance from toolbox (as described on 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 validate because ItemId is mapped in both parent and child entity. Delete ItemId from both Film and Game entities. You can also make Item entity Abstract and you will get this:

    enter image description here

    0 讨论(0)
提交回复
热议问题