locked
Entityframework code first Migration RRS feed

  • Question

  • Hi,

    First, sorry for my bad english. I'm developing an application with C# and EntityFramework code first and SqlCompact. The application is delivered to our customer in exe file format. 

    I manage the database with migration commands(Nuget). So, there are no problems  to update the database in my development environment when the entities must be changed(add new properties, change name of properties, ...).

    But, the problem I have is: how can I update the database of our customer without losing his data when I deliver a new version of the application to him, knowing that some entites have been modified(add new properties, removed some properties ...) ?

    Thank you in advance.

    Redwane


    deliver

    Beel

    Thursday, January 7, 2016 10:15 PM

Answers

  • Hi beela,

    >>there will be a problem of data loss when he will to testing the new version of the application, because the new database is empty and his older one is not empty. So, the execution of the application will remove his data.

    You could prepare some sql script such as insert into db1.table select * from db2.table. Backup customer history database before you run the application, then restore the history with another name such as db2, and then exectute the sql script restore customer’s history data.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 13, 2016 1:51 AM

All replies

  • Hi Beel,

    >>But, the problem I have is: how can I update the database of our customer without losing his data when I deliver a new version of the application to him, knowing that some entities have been modified (add new properties, removed some properties ...) ?
    It's not recommend to change data structure out of Entity Framework. It would bring mistake and spend more time to fix it. I create a demo on my side, the history data records are still existing after I migrate the database. The column of data records I removed would be lost.

    I would suggest you try to retrieve the changes which made by your customer and migrate them into your project to make sure it is under the control of Entity Framework or try to transfer data Manually for your customer to avoid any error maybe caused by the migration.

    Feel free to let me know if I have any misunderstanding.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 11, 2016 7:13 AM
  • Hi Herro,

    Thak you for your reply. But I don't change data structure out of Entity Framework. I work all time with Entity Framework.

    What I mean, we deliver to our customer a version of application in exe format file(we don't give him the source code) each big modification. This one work with those versions for testing.

    So, in the meantime, we continue to developing the application with new features. And certains modifications trains change of the model(changes of entities) in our development environment. Consequently, the database changes. And, when we deliver the new version to our customer, there will be a problem of data loss when he will to testing the new version of the application, because the new database is empty and his older one is not empty. So, the execution of the application will remove his data.

    Retrieving database from our customer is not possible for confidentiality reasons.

    I hope that my problem was explained correctly ?

    Sorry another time for my bad english.

    this one
    Consequently

    Beel

    Monday, January 11, 2016 10:24 PM
  • Code first migrations are intended to cover this scenario.

    Once you know that, there are a lot of resources you will be able to find if you search.

    For example:

    https://msdn.microsoft.com/en-us/data/jj591621.aspx?f=255&MSPPError=-2147217396

    http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Tuesday, January 12, 2016 3:39 PM
  • Hi Andy,

    With the two links that you propose, I see better how to guide my research now. I will investigate these links.

    Sorry If I had found the solution, or at least the research topic, I would not have wasted my time and that of others to post this question.

    So, maybe you are very experienced in this domain, it's good for you. But this is not the case for everyone. Especially for someone gradually discovers EF.

    I urge you not to take people for fools future

    In all cases, thank you a lot Andy for your reply.



    Beel

    Tuesday, January 12, 2016 4:07 PM
  • Hi beela,

    >>there will be a problem of data loss when he will to testing the new version of the application, because the new database is empty and his older one is not empty. So, the execution of the application will remove his data.

    You could prepare some sql script such as insert into db1.table select * from db2.table. Backup customer history database before you run the application, then restore the history with another name such as db2, and then exectute the sql script restore customer’s history data.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 13, 2016 1:51 AM
  • Hi Fred,

    Thank you too for your solution.


    Beel

    Wednesday, January 13, 2016 8:41 AM