I’m doing some simple things with EF4 and inheritance before I start the real work. I have tried it many ways and I can’t fix this.
I have two tables:
- reporting_Items (ItemId,etc)
- reporting_DataItems (ItemId,etc)
I need to keep the prefixes in the database tables because of coding convention.
Then I want to have the maped entities with the names Item and DataItem, and DataItem inherits from Items.
I did Database First and created the tables, but I removed the ItemId key from reporting_DataItems.
Then I generated the model from the database. It created the entities:
- reporting_Item
- reporting_DataItems
which I renamed to Item and DataItem respectively. Then I created the inheritance relation between DataItem and Item.
So up to this point I have the entities named like I want and the tables named like I want, plus the inheritance.
The problem is that if now I run Generate Database from Model it deletes all the tables and creates them with this names:
- Items
- Items_DataItem
Is there any way to acchieve what I want to do? Thanks in advance
You can use either database first (generated model from database or model first (generate database from model). Combining them is not supported because when you use model first it doesn’t use information about your original database. It uses its own conventions to name tables and it expects that you are going to use that new table names instead of old ones. Conventions can be changed but it means changing .tt template used to generate SQL.
So if you have existing database and you want to use it, never use Generate Database from model because this tool is not for your scenario.