Control table names Entity Framework Generate Database from Model
I was working with entity framework in a database first style. Each time I wanted to update m开发者_C百科y edmx file I did just that, ran update model.
The problem I now have is that I've lost my database (long boring story, it was on a disk that's been formatted and I don't have a backup). I thought I would be able to use the 'Generate Database from Model' option to at the least get the structure of my database back. The problem I have is that the tool automatically pluralises all the table names, so Cost
becomes Costs
and so on. This breaks the EF model as it is expecting the table Cost
so I can no longer run an 'Update Model from Database' as the table Cost
does not exist. How can I control the table tables that are used when generating a database from a model?
It turns out that the Entity Set Name
property was wrong for all of my entities, changing that to a non pluralised version gave me a sql script that created the tables in a form that could then be synchronised with the EF model.
If you want to stop EF from generating pluralized names, you can disable that by clicking on the empty space on your *.edmx file, and in Properties there is a field called "Pluralize New Objects" and change it from True to False.
精彩评论