EF Database first how to update the database change model?
The class library Ado.net Entity Data Model
has generated POCO classes. They were created perfectly the first time. But changes to the database are not reflected. In the dialog, edmx
right click and select Update Model from Database
to show the newly created table, but it doesn't add the table even after adding it.
I tried launching .tt (right click and launch a dedicated tool) but even it didn't restore the Poco classes to reflect the latest database changes.
help me please
source to share
Not a fix, but a workaround: isn't it possible to simply delete and regenerate the EDMX and generated classes? What I am doing is much simpler than working with the update function and the result seems to be the same. POCO extensions remain unchanged and functional.
I first use a database and I have my SQL update scripts generated by EDMX and my generated models in source control and the changes there are very easy to manage. Below is a quick overview of my database upgrade process for each version:
- Create a .sql script to update like
CREATE TABLE
etc. - Delete generated files: Model.Context.tt, Model.tt, Model.edmx
- Remove Entities line from Web.config (if you are using it)
- Create EDMX and Context files just like you did the first time
- If you are using source control (I hope you do!) Check what has changed.
- Test
- Commit!
source to share