如何使用 entity framework 6 迁移客户端数据库?

How to migrate client db with entity framework 6?

我在 MicroSoft local-db 中使用代码优先方法。直到现在,只有我开发和使用了我的程序。当模型改变时,我在包管理器控制台中使用了 add-migration 和 Update-Database。这里没问题。

现在其他人开始使用该程序。我使用 ClickOnce 部署。当程序有新版本时,将分发迁移的数据库。

我想迁移客户端的数据库,客户端数据应该不会丢失。我应该以某种方式从程序迁移,还是应该由 ClickOnce 来处理?有什么想法吗?

您可以在应用程序启动时运行迁移。

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