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

+3


source to share


3 answers


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!
+4


source


In my case, I needed to save ModelName.edmx, then the classes were generated.



0


source


Make sure the connection string in app.config is correct. I was using DataDictionary and my connection string had the following path:

data source=|DataDirectory|*.sqlite

      

So it hasn't been updated. As this DataDirectory variable was being resolved at runtime.

0


source







All Articles