locked
How to Update Model using code first if made changes Directly in database RRS feed

  • Question

  • User1765474751 posted

    As we know we can make changes in database using Code First migrations form model.
    But if i made some changes in Database directly as like insert new attributes to any table or Create new table Or Created some Relationships in ERD then how will I update Model from database using Code First?

    Tuesday, September 15, 2015 6:30 AM

Answers

  • User-821857111 posted

    You can't update your model from the database using code first. You will have to make the required changes to your model to keep it is sync with your database manually.  Then you can add a new migration, comment out the body of the Up method, and run the migration. That way the model snapshot stored in your database will reflect your code model.

    You shouldn't make changes directly to the database if you are using Code First. It's called Code First for a reason.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 15, 2015 8:26 AM