Marcin Gawlik
Marcin Gawlik

Reputation: 11

EF6 how to check if database model is newer than app model

I create an application where many clients use one database. When I create a migration, I have to update the applications to the latest version on all computers. Sometimes it is impossible at one moment. Clients then turn on my application and the application throws an error because it sees that the database is from a newer migration. How to check if the database is from a newer migration in EF6 to handle such an exception and display the appropriate message to the user? It is best to do it in Program.cs at the very beginning of the application start.

Thanks for any tips.

Upvotes: 1

Views: 273

Answers (2)

Randy
Randy

Reputation: 2358

Better to use a web app but if you must go the desktop or mobile native route then you can safeguard your application by forcing users to update.

You can create a table in your database as follows:

Application | CurrentVersion| MinVersion
  1. If Client.Version < Server.CurrentVersion then provide the user with optional upgrade notification
  2. If Client.Version < Server.MinVersion then force the user to upgrade

Upvotes: 0

Rithik Banerjee
Rithik Banerjee

Reputation: 467

You can find the actual version of a database in the migration history table __MigrationHistory containing a MigrationId column which should give you what you want. Here's an article showing how to work with it: https://msdn.microsoft.com/en-us/data/dn456841.aspx

Upvotes: 1

Related Questions