Entity Framework: regeneration of changed tables (key changes)

I have a pretty big DB connected to my Entity Framework. I have one specific set of tables in which the generic code (fk) has been removed from the project. When I “update the model from the database”, I get a series of errors about this now missing key.

Why does the update process not detect that this key has been deleted? Also, if I manually remove the property from the model, I just get other errors. I also tried just deleting the table and re-adding it, but now the table does not appear in the "Add" section of the update wizard.

So, if you don’t delete the whole thing and start, is there a way to restore grace? Has the EF team released new versions of this wizard that already have some of these issues?

+3
source share
1 answer

Entity Framework gets confused from time to time. What you need to do is remove the entity table from the model, and then rename the table in SQL Server to TableName_Temp, update the model, now the entity table should be fine, so delete the entity table, rename it back to the original name again and update the model again . Everything should be fine this time.

I know this is a confused procedure, but this is the only way to solve this problem without blowing away all edmx and starting from scratch. Currently, in my organization, we have a policy not to make changes to EDMX, if it is absolutely necessary, so that we can easily delete and recreate when necessary.

, !

+5

Source: https://habr.com/ru/post/1707205/


All Articles