Search code examples
entity-framework-coreentity-framework-core-migrations

keeping database in sync ef core


I have read multiple posts about this but do not have a clear answer yet. We are transitioning to EF Core 2.0 company-wide, one project at a time.

The challenge is this:

  1. A new project starts and a database is created using code first, migrations etc.
  2. another programmer needs to create a project targeting the same database.
  3. This programmer can use Scaffold-DbContext and generate current models.
  4. However, a new column is needed and this second programmer adds it.

Now...how do we best update the other projects? Is there something that checks and syncs or shows what is out of sync between your model and a database? Meaning check the database for changes...not the model.

We don't mind buying a tool if that is the best solution.


Solution

  • The solution we have been using, very successfully is the Database project in Visual Studio.

    Using that each developer has the project in their solution, changes are made against it locally. Then we can do a "Schema Compare" inside of VS.

    We have been using this successfully for 4 of us the past three weeks extensively with almost no issues.

    This has even worked for keeping versions and changes to our stored procedures current. It works well with VSTS also.

    Here are some of the posts I read that helped me understand it:

    https://www.sqlchick.com/entries/2016/1/10/why-you-should-use-a-ssdt-database-project-for-your-data-warehouse

    https://weblogs.asp.net/gunnarpeipman/using-visual-studio-database-projects-in-real-life

    ..and this forum had a lot of relevant questions/answers: https://social.msdn.microsoft.com/Forums/sqlserver/en-us/home?forum=ssdt