Check if applied migrations match the DbContext?
问题 I want to create a unit test to ensure no developer will commit model changes without the corresponding migration. How do I test that the database matches the DbContext? 回答1: You can leverage some of the lower-level Migrations components to do that: var migrationsAssembly = db.GetService<IMigrationsAssembly>(); var differ = db.GetService<IMigrationsModelDiffer>(); var hasDifferences = differ.HasDifferences( migrationsAssembly.ModelSnapshot.Model, db.Model); Assert.False(hasDifferences, "You