检查应用的迁移是否与DbContext相匹配?

编程入门 行业动态 更新时间:2024-10-18 06:06:41
本文介绍了检查应用的迁移是否与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相匹配?

本文发布于:2023-11-22 05:58:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616232.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:相匹配   DbContext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!