Reputation: 7527
I'm now using Entity Framework 4.3 DbContext to generate database entities, my question is when i change the database, how can i ensure the auto-generated code are updated? where does EF to store database rules, like allow null from No to Yes. When i use the Update Model From Database function from .EDMX file, it seems does not update the allow null rules of the table. How can i solve the database changes problem. Where is the code behind to store all these rules.
The error message:
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
But when i delete all EF auto-generated file and re-generate it again, it seems the rules are updated. But i thought it is not a good way to solve the problem during development period.
Upvotes: 1
Views: 1168
Reputation: 364249
When i use the Update Model From Database function from .EDMX file, it seems does not update the allow null rules of the table.
That is correct behavior. EDMX file has three parts:
When you use Update from database the designer will completely replace database definition and adds new tables or columns to mapping and class definitions. It will never try to remove or change anything. The reason for this is that class definition is customizable. If you make your changes you don't want designer to touch them. Update from database has only actual state - it doesn't know which changes were made by you and which changes are caused by modifying the database so it simply use the better way - don't modify anything and let you to correct inconsistencies.
Upvotes: 1