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

后端 未结 3 1497
[愿得一人]
[愿得一人] 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.

提交回复
热议问题