none
Downgrade or upgrade migration doesn't affect the code in .cs files RRS feed

  • Question

  • If we have an entity which have the three fields but due to some requirements, if we add a new column in it and add the changes in migrations but when we rollback that migration it remove the field form the database but doesn't remove it form the .cs file.

    for example:

    if we have an entity "Customer"

    class Customer

    {

    public string FirstName{get;set;}

    public string LastName{get;set;}

    public string City{get;set;}

    }

    now we have the requirement of adding a new column "State" in it.

    class Customer

    {

    public string FirstName{get;set;}

    public string LastName{get;set;}

    public string City{get;set;}

    public string State{get;set;}

    }

    To track the changes further, we add it migration using the "Add-Migration AddStateInCustomer" command, then it will create a migration file and to update the changes in database run the command "update-database" then it will create a new column "State" in database.

    But now due to some requirements, we have to rollback the changes. For this we rollback the migration by using the command "update-database -targetmigration:AddStateInCustomer". In this case it removes the column form the database but doesn't remove the code of your Customer class.

    According to me if we rollback the migration then it should also remove the property for the code.

    Please suggest


    MahiCRM

    Thursday, August 29, 2013 11:15 AM

Answers

  • Hello,

    Welcome toMSDN Support Forum.

    As far as I know what the Migrations do is just to create a SQL script for database.

    You can use command to see the created script like below:

    Update-Database -Script -SourceMigration: $InitialDatabase -TargetMigration: AddPostAbstract

    It would not modify the class code.

    If I have misunderstood, please let me know.

    I look forward to hearing from you.

    Best Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, August 30, 2013 6:01 AM
    Moderator