سؤال

i'm new to MVC and have to update my model.

I have an SQL Server database already connected to my project, today I add a new column. Now I need to update my MVC code to reflect the change.

Everything online tells me to update the .edmx and .tt files with the Update Model Wizard since they are auto generated, but I cannot find the wizard in VS 2012 so I am at a stand still.

Is this the right way I should be doing this? Any tips would be great...thanks

هل كانت مفيدة؟

المحلول 3

I ended up downloading this update of VS 2012 and repaired. Now I am able to update my model.

نصائح أخرى

There are a couple options you can do:

  1. If the database is empty or there isn't a lot of data that you care about, you can drop the database and recreate it.
  2. Manually add the column in the database (after property is in model)
  3. There is something called Code First Migrations. This will allow you to update your database. Here is a tutorial you can look at for this: http://msdn.microsoft.com/en-us/data/jj591621.aspx

Double click the edmx file. This opens the diagram of the database model. Right click and select "Update Model from Database..." That will start the wizard you're looking for.

Be aware that not all changes come through automatically.
Most obvious is that columns will not be removed from model just because they're gone from the db. If you're dealing with lots of modifications or deletes rather than additions, it may be best to just drop the model and recreate it (as suggested above by Andrew).
No matter which approach you take, I'd suggest making sure you have all other local source changes committed or shelved before starting because you may need to do an undo check out if EF gets freaked out.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top