如何在 Entity Framework 4.3 中禁用模型兼容性检查? [英] How can I disable model compatibility checking in Entity Framework 4.3?

查看:41
本文介绍了如何在 Entity Framework 4.3 中禁用模型兼容性检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 EF 4.3,并且有一个上下文需要与另一个库使用 EF Code First 4.3 生成的数据库进行对话.上下文正在抛出一个异常声明

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

支持上下文"上下文的模型自数据库已创建.考虑使用 Code First Migrations 进行更新数据库

The model backing the 'Context' context has changed since the database was created. Consider using Code First Migrations to update the database

在 EF 4.1 中,这可以通过从模型构建器中删除 IncludeMetadataConvention 来禁用.但是,在 4.3 中,此约定已被弃用,不再有效.

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.

如何让 EF 4.3 上下文与由不同上下文构建的 EF 4.3 生成数据库?我发现的唯一选择(远非理想)是删除元数据表,从而导致两个上下文假定数据库不是由 EF 构建的.

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:我知道这种情况可能会引起关于为什么我需要这样做的问题;我知道这远非理想,但请放心,这是一个我需要解决的问题,并且横向工作的选择有限.

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.

推荐答案

将初始化器设置为 null 将跳过模型兼容性检查.

Setting the initializer to null will skip the model compatibility check.

Database.SetInitializer<MyContext>(null);

这篇关于如何在 Entity Framework 4.3 中禁用模型兼容性检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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