How to migrate client db with entity framework 6?

Viewed 97

I use code first approach with MicroSoft local-db. Until now, only I developed and used my program. When the model changed I used add-migration and Update-Database in package manager console. No problem here.

Now others start to use the program. I use ClickOnce deployment. When there is a new version from the program, the migrated db is distributed.

I want to migrate the db of the client, client data should not be lost. Should I somehow migrate from the program, or ClickOnce should take care of it? Any idea?

1 Answers

You can run the migrations when the application starts.

If you are deploying your application you may want it to automatically upgrade the database (by applying any pending migrations) when the application launches. You can do this by registering the MigrateDatabaseToLatestVersion database initializer. A database initializer simply contains some logic that is used to make sure the database is setup correctly. This logic is run the first time the context is used within the application process (AppDomain).

Automatically Upgrading on Application Startup

Related