实体框架4.1的模型支持的背景已经改变,因为数据库创建,在创建数据库后,立即 [英] Entity Framework 4.1 The model backing the context has changed since the database was created, immediately after creating DB

查看:87
本文介绍了实体框架4.1的模型支持的背景已经改变,因为数据库创建,在创建数据库后,立即的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,它使用实体框架4.1坚持我们的各种对象的数据库(code第一)的一个项目。

I am working on a project which uses Entity Framework 4.1 for persisting our various objects to the database (code first).

我在Visual Studio本地SQL防爆preSS DB测试,我们的詹金斯服务器部署承诺code到测试服务器。当发生这种情况我暂时改变我的本地连接字符串,使其指向测试数据库服务器并运行单元测试来重新创建测试数据库以便它匹配我们最新的实体,等等。

I am testing in Visual Studio with a local SQL Express DB, and our Jenkins server deploys committed code to a testing server. When this happens I temporarily change my local connection string to point to the testing DB server and run a unit test to re-create the test database so that it matches our latest entities, etc.

我最近注意到我们的测试服务器是给这个错误:

I've recently noticed our testing server is giving this error:

模型来头EntityFrameworkUnitOfWork'环境已经改变,因为该数据库已创建。无论是手动删除/更新数据库,或致电Database.SetInitializer与IDatabaseInitializer实例。例如,DropCreateDatabaseIfModelChanges战略将自动删除并重新创建数据库,以及可选的新的数据种子吧。

这通常是我们的code已经改变的指示,我需要运行单元测试来重新创建数据库。但我只是做了!我不相信有什么毛病我们的部署过程 - 在测试服务器上的DLL文件似乎是相同的版本在我当地的环境。是否有任何其他设置或环境因素可能会导致这个错误有关的模型,因为数据库的创建已经改变?

This is usually an indication that our code has changed and I need to run the unit test to re-create the database. Except I just did that! I don't believe there is anything wrong with our deployment process - the DLLs on the test server seem to be the same versions as in my local environment. Are there any other settings or environment factors that can cause this error about the model having changed since the database was created?

我是新来 - !感谢您的帮助。

I'm new here - thanks for any help!

推荐答案

您看到的错误意味着存储在 EdmMetadata 模型哈希表是从计算模型哈希不同从应用程序中的模型。因为你是从不同的应用程序运行的数据库创建(你的开发。应用程序)有可能是这两个不同。这里简单的建议是:不要使用数据库创建不同的应用程序,而是让你的主应用程序创建数据库(自动或与一些管理界面的例子)。

The error you see means that the model hash stored in EdmMetadata table is different from the model hash computed from the model in the application. Because you are running database creation from a different application (your dev. application) it is possible that those two differ. Simple advice here is: don't use different applications for database creation and instead let your main application create the database (either automatically or for example with some admin interface).

正如你应该能够通过删除负责这些检查公约完全关闭这个检查另一个选择:

As another option you should be able to turn off this check completely by removing the convention responsible for these checks:

modelBuilder.Conventions.Remove<IncludeMetadataConvention>();

示范哈希计算是依赖于你的应用程序当前实体(任何简单的变化导致不同的模型哈希值)以及数据库服务器版本/清单。例如,一个模型部署SQL Server 2005和2008年将有不同型号的散列(前preSS与全或2008与2008 R2不应导致不同型号的哈希值)。

Model hash computation is dependent on current entities in your application (any simple change result in different model hash) and on database server versions / manifest. For example a model deployed on SQL server 2005 and 2008 will have different model hash (Express vs. Full or 2008 vs. 2008 R2 should not result in different model hash).

这篇关于实体框架4.1的模型支持的背景已经改变,因为数据库创建,在创建数据库后,立即的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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