簡體   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