locked
Update Model from Database not working RRS feed

  • Question

  • My .edmx model and entities will not update when I right click and select 'Update Model from Database...' I don't understand it. I have like 40 tables in this database and I'm using EF Database First Approach. If I delete one of the tables from the model, it warns me that this table will no longer be mapped and I delete it.
    Then I add the table back by right clicking and selecting 'Update Model from Database...' because now it sees it as not being mapped. When it adds it back, I see all the new fields in the table. I don't think I should have to delete every table in my model every time fields or the schema changes. Why doesn't this work?

    I've tried it on a smaller scale. I created a new database with one table. Added a field in the backend and 'Update Model from database' worked. I saw the new field. But not on my bigger database.


    Thanks for the advice!
    Friday, July 8, 2016 11:23 PM

Answers

  • Hi HTHP,

    >>Then I add the table back by right clicking and selecting 'Update Model from Database...' because now it sees it as not being mapped. When it adds it back, I see all the new fields in the table. I don't think I should have to delete every table in my model every time fields or the schema changes. Why doesn't this work?

    According to your description, as you said. you delete one entity from Edmx file. then add a field on the table in your database. add the entity by using ''Update Model from Database', it doesn't work. does it? I create a simple demo with 40 tables, do the same active as you said, it works, I could encounter the issue that you occurring. My development environment is: Ef 6.13 and .net framework4.5.1.

    If you update the model with the existing model, you could use refresh tag. For more information, please refer to:

    https://msdn.microsoft.com/en-us/library/cc716697(v=vs.100).aspx

    In addition, if the issue is still exist, please delete the edmx file, then add it again and check if it works for your.

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 11, 2016 5:09 AM

All replies

  • My .edmx model and entities will not update when I right click and select 'Update Model from Database...' I don't understand it. I have like 40 tables in this database and I'm using EF Database First Approach. If I delete one of the tables from the model, it warns me that this table will no longer be mapped and I delete it.
    Then I add the table back by right clicking and selecting 'Update Model from Database...' because now it sees it as not being mapped. When it adds it back, I see all the new fields in the table. I don't think I should have to delete every table in my model every time fields or the schema changes. Why doesn't this work?

    I've tried it on a smaller scale. I created a new database with one table. Added a field in the backend and 'Update Model from database' worked. I saw the new field. But not on my bigger database.


    Thanks for the advice!

    I have never had a problem with this in DB First with 100 object or more sitting on the virtual model, and I can't fathom what the problem could be. 
    Saturday, July 9, 2016 3:24 PM
  • Hi HTHP,

    >>Then I add the table back by right clicking and selecting 'Update Model from Database...' because now it sees it as not being mapped. When it adds it back, I see all the new fields in the table. I don't think I should have to delete every table in my model every time fields or the schema changes. Why doesn't this work?

    According to your description, as you said. you delete one entity from Edmx file. then add a field on the table in your database. add the entity by using ''Update Model from Database', it doesn't work. does it? I create a simple demo with 40 tables, do the same active as you said, it works, I could encounter the issue that you occurring. My development environment is: Ef 6.13 and .net framework4.5.1.

    If you update the model with the existing model, you could use refresh tag. For more information, please refer to:

    https://msdn.microsoft.com/en-us/library/cc716697(v=vs.100).aspx

    In addition, if the issue is still exist, please delete the edmx file, then add it again and check if it works for your.

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 11, 2016 5:09 AM
  • The issue is that deleted table columns aren't removed from the model with "update from database".

    Steps to reproduce:

    1. Create a database in SQL server first, with a bunch of columns of various types.
    2. Create the EDMX from Visual Studio 2015 using latest EF6 version.
    3. Build project.
    4. Go back to SQL server and remove a couple random columns from the table and save.
    5. With the EDMX open in VS, right-click > Update Model from Database, then save the EDMX.
    6. Observe errors that the columns you removed are not mapped, and they still show in the diagram.
    7. --  Note that you may have to close and reopen the EDMX to see the errors.
    8. Manually remove each column from the model diagram, save, close, and reopen the EDMX.
    9. Observe the errors are gone.

    We should not have to perform step 8 by hand, nor should we have to remove dozens of tables and add them back to the model. In large projects, that's cumbersome and prone to user error.  If the element is gone from the database, it must be removed from the model.


    Monday, January 16, 2017 7:27 PM
  • Not just deleted. Even if the type is modified, the problem exists. I ran ALTER TABLE DROP COLUMN on a couple of nvarchar columns and re-added them as DateTime, the edmx NEVER picked up the change. I even tried just running the DROP column and 'update from database' and the edmx did not remove them. I had to manually delete them.
    Wednesday, June 12, 2019 2:38 PM