3

Need help! I am new to Core 2.0 and VS 2017 and haven't had much experience with MVC. I have an existing database that I need to use with a core 2.0 project at work. I was able to use the Scaffold-DbContect to initially create the domain models from the existing database.

However, the database developers are making changes to the database and adding new tables. I need to keep my domain models in sync with the database changes that are being made.

The only thing I can find on the internet is how to make changes to the model and update the database schema. However, I need to update the model from changes made to the database.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197

1 Answers1

1

EF Core works on Code First approach. And You guys are following DB First approach together. So you should make changes in your code and then generate migrations accordingly, Otherwise, it will lead you in trouble.

You can use EF Core Power tool for generating the db changes at code side. But in this case you have to take care while generating migrations from code side.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
  • Thanks for the feedback! The ability to use code first migration to keep it in sync is not possible. The database services several other applications and database changes are managed by the db team. – CJohn Ransom Apr 20 '18 at 17:30
  • In that case you have two options. Either generate model classes using reverse engineering or don’t use EF Core – Vivek Nuna Apr 20 '18 at 17:36
  • Thanks for the feedback! The ability to use code first migration to keep it in sync is not possible. The database services several other applications and database changes are managed by the db team. When changes that effect the core 2.0 application are made to the database by the db team I need to be able to update the domain models to reflect the changes. Under no circumstance can the application make changes to the database schema. So the question is how do I accomplish this. Is there a manual way to keep them in sync? – CJohn Ransom Apr 20 '18 at 17:39
  • Do you know of any examples or articles on how to generate model classes via reverse engineering? – CJohn Ransom Apr 20 '18 at 18:00
  • I don’t have any example, but I have used it, its really very simple. – Vivek Nuna Apr 20 '18 at 18:21
  • https://marketplace.visualstudio.com/items?itemName=ErikEJ.EFCorePowerTools You can download it from – Vivek Nuna Apr 20 '18 at 18:23
  • Thanks! Will look at it and do some testing. – CJohn Ransom Apr 20 '18 at 18:51
  • Sure, let me know if u need help. – Vivek Nuna Apr 20 '18 at 18:52