如何禁用Entity Framework 4.3中的模型兼容性检查? [英] How can I disable model compatibility checking in Entity Framework 4.3?
问题描述
自
数据库创建以来,支持上下文上下文的模型已更改。考虑使用代码优先迁移来更新
数据库
在EF 4.1中,可以通过删除 IncludeMetadataConvention
从ModelBuilder。但是,在4.3中,这个约定已被弃用,不再有效果。
我如何在EF 4.3生成的数据库中具有EF 4.3上下文交流?由不同的上下文构建?我发现(唯一不太理想)的选项是删除元数据表,从而导致上下文假定数据库未由EF构建。
PS:我知道这种情况可能会引发关于为什么我需要这样做的问题?我知道这远远不是理想的,但放心,这是一个我需要解决的问题,并且有限的选择可以在横向工作。
将初始化器设置为 null
将跳过模型兼容性检查。
Database.SetInitializer< MyContext>(空);
I'm working with EF 4.3 and have a context which needs to talk to a database which was generated by another library using EF Code First 4.3. The context is throwing an exception stating
The model backing the 'Context' context has changed since the database was created. Consider using Code First Migrations to update the database
In EF 4.1 this could be diabled by removing the IncludeMetadataConvention
from the ModelBuilder. However, in 4.3 this convention has been deprecated and no longer has an effect.
How can I have an EF 4.3 context talk to an EF 4.3-generated database built by a different context? The only option I've found (which is far from ideal) is to delete the metadata table, thereby causing both contexts to assume the database was not build by EF.
PS: I know this scenario is likely to raise questions about why I need to do this; I know it's far from ideal, but rest assured it's a problem I need to solve and have limited options to work with laterally.
Setting the initializer to null
will skip the model compatibility check.
Database.SetInitializer<MyContext>(null);
这篇关于如何禁用Entity Framework 4.3中的模型兼容性检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!