Core 2 Keep domain models in sync with database changes

asp.net-core-2.1 database-first ef-migrations entity-framework-core

Question

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.

1
3
4/20/2018 4:01:01 PM

Accepted Answer

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.

1
4/20/2018 5:53:08 PM

Popular Answer

I have similar kind of situation. Someone have already design and build the database (56 tables) in SQL Server, and he has already left now. I am creating web application using that database. I prefer to do EF code first approach so I can control the database from the code. Problem is, it is taking bit of time to create all the tables with relationships, constraints, and there some name conventions, bit refactoring needs to be done which is hard to do if follow the database first approach. I estimated around it is work of one week (5 business days), but challenge, how can I agree my IT manager because he is more concerned that if we invest 1 week of time, does it worth? we we need to do that.

Can someone please list out real advantages of code first approach, and the problems that we will face with database first approach.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow