EF code first and efcodefirst
In the actual project, you may have designed the database and want to use EF code fist. You can add ADO in the project. select code first from the database when using the. NET object model. The model is automatically created based on the database table,
If you need to modify the table structure, you can directly modify it in the model. After the modification, You need to synchronize it to the database. You can follow the steps below to set it,
1. Enter enable-migrations in the VS package management console. After it is enabled, a directory named Migrations will be created in the folder.
2. In Configuration. cs generated in 1, modify the constructor code to: "AutomaticMigrationsEnabled = true;" ContextKey = "EFTest. TestModel ";
3. After saving the changes, enter "Update-Database-Force" in the "package management console", Press enter, and run again.
If an error occurs that the table already exists, delete or rename the table for the first time, and then run the table again. This error will not occur after modification, the existing database records are not deleted.