本文介绍了检查应用的迁移是否与DbContext相匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个单元测试,以确保没有相应的迁移,任何开发人员都不会提交模型更改。
I want to create a unit test to ensure no developer will commit model changes without the corresponding migration.
如何测试数据库与DbContext匹配?
How do I test that the database matches the DbContext?
推荐答案您可以利用一些较低级别的Migrations组件来做到这一点:
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 forgot to add a migration!");更多推荐
检查应用的迁移是否与DbContext相匹配?
发布评论