EF6 Schema compare between database and sql-file?

ef-migrations entity-framework entity-framework-6 sql sql-server


I use EF6 model-first approach to design MS SQL database by using "Generate database from model..." in Visual Studio. This generates a sql-file with all drop and create statements.

At some productive stage where the database is filled with records, I do not want all tables to be dropped and recreated, their scheme should be updated in place without the need to backup and restore all records. That's where I found EF Migrations would be useful.

As I read, EF migrations are only suitable for code-first approach - so not what I need.

Next stop is the Schema Comparison Tool in Visual Studio, from which I think, it could fit. But unfortunately I do not have 2 databases to compare, what I want to compare is the existing database to the new EF model (or the SQL-file generated out from that) to get a SQL-file for deploying only changes of tables.

Is this possible at all and if yes - where do I have to look at?

2/23/2020 11:59:06 AM

Accepted Answer

There isn't an EF tool for this from Microsoft, not like they built for SQL projects and dacpacs.

We had a similar need to ensure production schemas didn't differ to the point of runtime errors so I wrote one: https://github.com/reckface/EntityFramework.Verify

It's covered in this Code review question. It doesn't generate any SQL to fix the differences, but does notify you of the differences.

4/19/2019 8:05:18 AM

Related Questions


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