VS 2012 - EF 5.0 - Update Model from Database - Not picking up table changes

entity-framework visual-studio-2012

Question

In Visual Studio 2010 EF 4, I could add a new column to a database table, then click 'Update Model from Database' on my .edmx and all was good in the world.

In Visual Studio 2012 EF 5, I alter a table, and then click 'Update Model from Database' and it does not pick up the changes to individual tables anymore.

Am I missing something ... or is this a new 'feature' of VS2012?

Update The only way I can get a table with an added column to reflect in the .EDMX file is to delete the table then 'Update Model from Database' and it will pick up the added column. However, it puts the added table far off to the left and I have to move it back in place. No biggie just an annoyance.

1
9
10/24/2012 5:28:53 PM

Accepted Answer

There is a difference between having an EF Model and how it is underlined in your database. When you "Update model from database", if the entity/table is already imported into your data model then you will be refreshing the entity. This process will not automatically map your database schema to your existing data model, you can however add a property to the entity in your EF model, and then map the property to the database column (this is exactly what EF does for you automatically when you delete and update normally).

When you delete the entity first, then update EF knows that the table/entity has not been imported before and so will map all of the database columns automatically for you.

In summary, you don't HAVE to delete the entity, but it can be easier to do so for simple entities.

2
10/25/2012 10:16:01 AM

Popular Answer

Yes, this still works in VS2012. Are you using the default code generation or do you have a TT file? It could be that it's being added to the EDMX but your class files are not being updated.

Try right-clicking on the EDMX file or the relevant TT file in Solution Explorer and choose "Run Custom Tool" to make sure it's being regenerated.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow