Entity Framework and Migrations - dibley1973/OpenRMS GitHub Wiki
Entity Framework 7 is currently implemented as an ORM to map the domain model to the data model.
In order to manage and track incremental changes to the database the migrations tool of EF is used. The application is currently configured to implement all unimplemented migrations upon startup, via the call to Database.Migrate().
Should you make any changes in the domain model, before the application is able to apply them you must create a migration using the ef command line tooling. To do this use the following steps...
- Open a command line window
- Navigate to the infrastructure project of the bounded context that you have made the change
- Run the following command, swapping the relevant parts for the configuration you require:
dotnet ef -s ../OpenRMS.Contexts.ItemManagement.ApplicationService migrations add address_field -o PostgreSql/Migrations
This will create a migration called "address_field" to the item management context, and place it in the PostgreSql/Migrations folder of the infrastructure project you are currently within. The -s parameter specifies the project which contains the Startup.cs file, which is required in order for the migration to run. The -o parameter specifies the output directory where the migration will be generated.
Once your migration has been created, as mentioned above, the application will apply it on startup.
If you have already created a database environment previously, you will be required to destroy and recreate your database server (via vagrant) in order for the initial migration to be applied successfully.