Skip to content

9. EfSchemaCompare

Jon P Smith edited this page Apr 22, 2019 · 18 revisions

9. EfSchemaCompare - How to ensure EF Core's view of the database matches the actual database

This feature allows you to compare what EF Core thinks the database schema looks like against what the actual database scheme is. This can be useful in a couple of places:

  1. If you are changing the schema of your database outside of EF Core' migrations, say by using SQL change scripts, then you can use this feature to check that the changed database is in step with EF Core's model of the database.
  2. This feature can quickly tell you if your EF Core code has changed in any way that would mean it won't work with a database. This can be useful to run before deploying a new software version to a production database to check it will still work.

I personally use the EFSchemaCompare feature to allow me to create/migrate the database via SQL change scripts, using DbUp. I find this a good way to handle a database, especially in production environments.

NOTE: I describe example 1 in chapter 11, section 11.4.3 in my book Entity Framework Core in Action, with is where the figure below comes from.

EfSchemaCompare diagram

FIGURE showing how EfSchemaCompare works.

Further information

See 9a. EfSchemaCompare config for the configuration options available. These allow you to

  • Exclude specific tables in your database that you do not want compared with EF Core.
  • Turn off certain errors through building an 'ignore' matching CompareLog.
Clone this wiki locally