Entity Framework : How do you refresh the model when the db changes?

前端 未结 9 949
囚心锁ツ
囚心锁ツ 2020-12-01 01:56

If you build the edmx file from the database and then the db changes, how do you get the model to pick up the change?

Do you delete the whole model and regenerate or

9条回答
  •  爱一瞬间的悲伤
    2020-12-01 02:24

    Update CodeFirst Model is not possible automatically. I don't recommend either. Because one of the benefits of code first is you can work with POCO classes. If you changed this POCO classes you don't want some auto generated code to destroy your work.

    But you can create some template solution add your updated/added entity to the new model. then collect and move your new cs file to your working project. this way you will not have a conflict if it is a new entity you can simply adding related cs file to the existing project. if it is an update just add a new property from the file. If you just adding some couple of columns to one or two of your tables you can manually add them to your POCO class you don't need any extra works and that is the beauty of Working with Code-First and POCO classes.

提交回复
热议问题