Say you send a new app version to customer, and you need to update the local customer database, say its an SQL microsoft database 2008.
-
For now i do this by a version table in the database, and run,
sql scripts. – to match that version, like:if (DatabaseVersion < Common_func.ProgramDBFixVersion) { switch (DatabaseVersion) { case 0: if (Fix0() == false) NoErrorFixFlg = false; goto case 1; case 1: if (Fix1() == false) NoErrorFixFlg = false; goto case 2; . . . private static bool Fix1() { try { var conn = new SqlConnection(Utils.ConnectionString); conn.Open(); ExecSql(conn, "ALTER TABLE Customer ADD Is_Deleted [bit] NULL"); conn.Close(); } catch (Exception ex) { retrun false; } return true; }
This work good, but is there any real built in support to this in the Entity Framework.
without any data loss !
If so – can you give some concrete example how this can be done the right way.
Thank you so much!
Check out migrations: http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx
When using without automatic updating, each migration / change is created in a file with scripted changes and rollbacks