How to keep your data when model changes?

Christopher Pisz

I am learning entity framework. I am reading through some tutorials about initialization and how there are

  • CreateDatabaseIfNotExists
  • DropCreateDatabaseIfModelChanges
  • DropCreateDatabaseAlways
  • Custom DB Initializer

to choose from.

This makes me wonder, what does one do when they want to change the schema, but they want to keep the data they have?

I was just using sql directly, I could make temp tables, move stuff over, recreate the table with new columnns, move stuff back, etcv

What do you do when your classes and/or their relationships change in EF?

hujtomi

I think your looking for EF migrations: https://docs.microsoft.com/en-us/ef/ef6/modeling/code-first/migrations/

for every schema change you create a migration, where you can add or remove tables or columns, or you can even run your custom script.

Each migration has an Up method, these will be applied if you run your migration, and a Down method this is used if you want to roll back to the previous migration for some reason.

With Update-Database you can apply all migrations, and with Update-Database –TargetMigration:{nameOfMigration} you can migrate to a specific version.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to refresh the view when data changes in model?

How to keep values in disabled input control when model changes?

How to keep default scope data even when scope data changes?

How your data is safe in Hyperledger Fabric when one can make changes to couchdb data directly

Docker: How to update your container when your code changes

How to keep information about multiple changes related to a model

How to keep your terminal running when laptop lid is closed

How to force validation to run on model when other model changes?

How to keep some text relative to the line into the plot when the plot changes

How to keep the same fragment when rotation changes with using viewmodel?

How to keep margin top constant when Div's height changes

How to keep vlcj consistent when layout changes in JavaFx

Notify property change defined in the ViewModel when underlying Model data changes

How to keep reference of data when using ObservableObject

VueJS - How to scroll bottom when data changes

Keep data in relational data model

How to keep changes made by Heroku to Discord Python app when adding changes?

How to track WHEN a model attribute changes using Rails 4?

how to populate database fields when model changes in django

AngularJS: How to change radio button view when model changes?

How to fire an event when v-model changes?

How to call the function in the class model when the field changes?

How do you clear form inputs when a model changes in AngularJS?

How to avoid program exception when ef model changes?

How to deal with JavaFX's threading model and large data changes

How to merge and keep my changes?

How to keep the changes made to a parameter?

How to update UI when data changes in data-binding android?

How to use color() instead of facet_grid() to 'split' your data but keep it on the same plot