接收“支持”上下文“上下文的模型已经在EF 5升级后的添加迁移中发生了变化 [英] Receiving "The model backing the 'Context' context has changed... on Add-Migration after EF 5 upgrade

查看:119
本文介绍了接收“支持”上下文“上下文的模型已经在EF 5升级后的添加迁移中发生了变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用代码优先迁移构建应用程序。我们一直在使用Entity Framework 5.0.0 RC,我们更新了实体框架的NuGet软件包。数据库已经与模型上下文保持一致。代码第一次迁移已经工作了好几个月。

We are building an app using code-first migrations. We had been using Entity Framework 5.0.0 RC, and we updated our NuGet package for Entity Framework. The database has been in sync with the models context. Code first migrations have been working fine for months.

当我们修改我们的模型,并尝试添加迁移,甚至查询迁移时,我们收到System.InvalidOperationException为模型的背景改变。

When we modify our models, and try to add a migration, or even query for migrations, we receive the System.InvalidOperationException for the model backing changed.

很明显,我试图添加一个迁移。

Well, obviously it has, I'm trying to add a migration.

我们不知道从这里做什么。如果我删除这些更改,我可以成功运行Get-Migrations,并显示数据库已正确应用所有的迁移。虽然ProductVersion列说5.0.0-rc.net45。

We're not sure what to do from here. If I remove the changes, I can run Get-Migrations successfully and it shows that the database has all the migrations applied correctly. Although the ProductVersion column says "5.0.0-rc.net45".

有没有人遇到这个问题?

Has anyone else experienced this problem?

推荐答案

找到它。这个问题的根源是在我们的构造函数中为同一个类设置 DbContext.CommandTimeout 的代码,如这个其他问题。访问该属性开始一个初始化过程,这给我们提供了我们实际调用的命令尝试解决的错误。

Found it. The source of this problem was code that set the DbContext.CommandTimeout in our constructor for the same class, like in this other question. Accessing that property started an initialization process that was giving us the error of what the command we actually invoked was trying to solve.

这篇关于接收“支持”上下文“上下文的模型已经在EF 5升级后的添加迁移中发生了变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆