Entity Framework: Semi-automatic Migrations
Entity Framework: Semi-automatic Migrations
Your app alerts the user if the database has not being created yet or has changes, then they can create or update from runtime. Works for EF 6 and .NET 4.8.
-
Clone or download the code
https://github.com/atorres16/EF-semi-automatic-migrations.git -
To setup the environment for development, set the connection string in app.config
<connectionStrings> <add name="Db" connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=Dev_TestDB;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/> </connectionStrings>
-
Add an initial migration
add-migration init
-
Update the database. This will create a database only for development purposes
update-database
-
Run the app and you’ll get:
-
Set a connection string for production
-
Restart the app, you’ll get:
-
Click “Create Database”:
-
Check your database, you’ll see the end user database created
-
Modify the model, add a property to Thing
public class Thing
{
public int Id { get; set; }
public string Property1 { get; set; }
}
-
For your development environment, add a migration and update the database
add-migration property1 update-database
-
Run the app, you’ll get:
-
Click “Update database”:
Comments
Post a Comment