0

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!

1
  • Wow, I never knew you could do goto case in C#. Though strangely I don't feel like I've missed out on anything. Commented Apr 19, 2013 at 6:59

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.