why does visual studio delete my classes when I update entity framework model

后端 未结 3 1498
[愿得一人]
[愿得一人] 2021-02-15 23:45

I\'m having a strange problem when I update my EF model (ver 5). It deletes all of the classes that belong to that model.

My situation was like this. I changed the key

相关标签:
3条回答
  • 2021-02-15 23:49

    One way this happens after removing then re-adding a table to get EDMX to pick up a change to a Foreign Key (FK) column.

    It happens because the relationships to other tables are not refreshed.

    Per this answer, https://stackoverflow.com/a/34144341, to manually fix this, filter the Error List by "Build Only", and then manually resolve any build errors in the EDMX editor. Pay attention to the multiplicity of the relationships.

    Alternately, use version control to revert the whole EDMX change and start again, using the following approach:

    Rather than removing and re-adding only the table containing the FK column that changed, remove and re-add all tables that have any relationship to any FK column that changed.

    0 讨论(0)
  • 2021-02-15 23:49

    It's been a long while, but in the end it turned out I had some errors in my edmx file which I hadn't seen, and that was causing the poco class files to not be generated.

    0 讨论(0)
  • 2021-02-16 00:15

    The same thing happened to me. I had a table with a string value but I wanted to change this to a foreign key so that I could store the reoccurring string values in a separate table. So I created a new table and I changed the string column type to a not nullable int and added a foreign key. When I updated the model, it marked all entity classes as deleted... not funny.

    I also saw some errors popping up indicating that EF didn't change the column type from string to int.

    The solutions mentioned above (the custom tool and transforming all templates) did not work for me.

    For me the solution was to change the column type from string to int manually in the model first and then updating the model, no more issues occured.

    For the record: this happened in EF 4 in Visual Studio 2010.

    0 讨论(0)
提交回复
热议问题