1

I am using code first entity framework approach. I have changed the name Plane_EcoClass to Plane_Class property to the table in the database. It is showing with old property name in the db .How can I update the new property name?. Please let me know how to resolve this error.

public class Plane
   {
    [Key]
   public int Plane_id { get; set; }
   public string Plane_Name { get; set; }
   public string Plane_No { get; set; }
   public string Plane_Class { get; set; }
   public virtual List<User>Users { get; set; }
   }
1
  • You need to give more detail within your question to help others help you. I'd suggest you take a look at stackoverflow.com/help/how-to-ask, and edit your posting. Commented Mar 30, 2018 at 16:36

1 Answer 1

2

you need to add a migration and update the database for the change to affect the database. In the package manager console, type something like:

add-migration YourMigrationName

to create the migration. Review the migration code. Be aware that Entity Framework may try to drop the previously named column and add a column for the new name. This can potentially cause data loss. If this is the case and not desired, then you can manually change the code to use the RenameColumn method. After adding the migration, you can apply it to the database by going back to the package manager console and typing:

update-database

and then hitting enter. At this point, the package manager console will give you some output regarding running migrations and your seed method and then the database should reflect the updated column name

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.