2017-03-26 12 views
1

エンティティフレームワークセクションを含むweb.configファイル設定があります。Asp.net Web.config Entity Frameworkセクションの変換挿入セクション

Web.configファイル

<configuration> 
    <configSections>   
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
</configuration> 

しかし、私はデバッグ中に、データベースの初期化子を使用します。だから私はWeb.Debug.configファイルのエンティティフレームワークセクションを使用したいと思います。 xdt:Transform="Insert"

Web.Debug.configファイル:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <entityFramework> 
    <contexts xdt:Transform="Insert"> 
     <context type="MyProject.DashboardContext, MyProject.Data"> 
     <databaseInitializer type="MyProject.ContexttInitializer, MyProject.Data"></databaseInitializer> 
     </context> 
    </contexts> 
    </entityFramework> 

は、しかし、これはContexttInitializerクラスを実行しません。 Web.configファイルにこのセクションを追加すると、このセクションが実行されます。

+0

あなたは右のVisual StudioのソリューションエクスプローラでWeb.Debug.configをクリックして、変換をテストし、コンテキスト要素があなたの変換ウェブに挿入されていることを確認することができます.config –

+0

デバッグトランスフォームを使用する場合は、サイトをデバッグサーバーにデプロイするか、単にF5キーを押してアプリケーションを実行しますか? – DavidG

+0

はい、F5でデバイギングします。設定は正しいですか? – barteloma

答えて

0

Visual Studioはデバッグ構成変換を使用しません。これは、ベースweb.configファイルのみを使用します。必要な作業は、ベースファイルにEntity Frameworkの設定を追加し、リリース版で削除することです。たとえば、ご使用のリリースの設定:

<entityFramework> 
    <contexts xdt:Transform="Remove" /> 
</entityFramework> 
関連する問題