Extend Database Initializer

The Entity structure has three initializers, of which I know - CreateDatabaseIfNotExists, DropCreateDatabaseWhenModelChangesand DropCreateDatabaseAlways. When the model changes, they either discard all data or die.

I want an initializer that extends an existing database in accordance with the model. If the table is missing, create it, if some columns have changed, rename them and create new copies, etc. Naturally, there are many questions, in particular when it comes to links, but I'm sure something more reasonable than deleting data can be done.

Is there such an initializer? If not, how can I write one?

To clarify, I want to read the changes detected by EF, and if, say, the column has changed from intto double, I want to make changes, saving my data. Complex interactions between support columns do not need to be considered.

+3
source share
2 answers

You can find a couple of database initializers similar to what you want to do in this thread

Great source of information, of course, the sources of EF :

There are many database initializers in test projects. There's also a bonus: DbContext for SQL metadata in a file $\test\EntityFramework\FunctionalTests.Transitional\Migrations\TestHelpers\InfoContext.cs: you can query sql metadata using linq.

+3
source

All Articles