繁体   English   中英

在EF4.3.1代码优先迁移期间如何忽略派生的DbContext

[英]How to ignore derived DbContext during EF4.3.1 Code First migration

我正在尝试使用代码优先的迁移,但是包含我的CustomContext的项目也有一个派生类TracingCustomContext,我在跟踪生成的SQL时会使用它:

DbContext => CustomContext => TracingCustomContext

我在代码优先迁移过程中遇到的问题是尝试运行时

Enable-Migrations

在Package Manager控制台中,这将导致(并非意外)警告:

More than one class deriving from DbContext found in the current project.
Edit the generated Configuration class to specify the context to enable migrations for.

为了摆脱此消息并继续执行Add-Migration -Initial,我必须注释掉TracingCustomContext类,然后运行Enable-Migrations。 生成的Configuration类看起来不错,因此警告中的建议似乎并不相关。

因此,我的问题是是否有任何方法可以配置迁移,因此它会忽略特定的上下文(例如TracingCustomContext)? 例如,用于装饰类的属性,还是某个地方的配置设置?

任何想法表示感谢。

根据错误消息:

Edit the generated Configuration class to specify the context to enable migrations for.

打开创建的Configuration.cs类(位于Migrations文件夹中),您将看到:

internal sealed class Configuration : DbMigrationsConfiguration</* TODO: put your Code First context type name here */>

替换/ * TODO:将您的Code First上下文类型名称放在此处* /中,并使用上下文的类型名称(在Seed方法中执行相同操作,或者如果不使用它,则删除Seed方法),它应该可以工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM