In the EF framework, how to solve the problem that the database data is not synchronized to the program when the field is manually updated in the entity?

In the hands of some players who are not very strong in technology, when designing the database, it is inevitable that certain fields will not be considered. Only when the function is implemented later can you notice that there are fewer fields in the database or more unnecessary fields. So we still have to do some tricks in the database.

This article lists in asp mvc. When you use the EF framework to map all the entities, you suddenly find that there are fewer fields in the database. You can add it impatiently. Try to add it with a happy mood. The result What if the field is updated synchronously, but the data is not updated synchronously?

Add a new field in the entity class:

public Nullable<int> mtiaozhanjin { get; set; }

The data in the database:
Insert picture description here
But the result of executing the application is this:
Insert picture description here
What should I do? It has been solved for a long time, and there is no online search. Finally, I figured it out by myself. The following is the specific method:

1. Open the relationship diagram:
Insert picture description here
2. Right-click on the design diagram and click the menu [Update Model from Database]:
Insert picture description here
Then it is ok.
Insert picture description here
Welcome to pay attention to the public number ~
Insert picture description here

Published 691 original articles · praised 649 · 1.11 million views

Guess you like

Origin blog.csdn.net/qq_34137397/article/details/105310894