4

UI レイヤー、ビジネス ロジック レイヤー、インフラストラクチャ レイヤーという従来のアーキテクチャを持つ WPF アプリケーションを作成しています。構成を 2 つのファイルに分割することにしました。共通のアプリ構成を含む app.config ファイルと、ドメイン モデル ストレージ用に DbContext で使用する接続文字列を含む dll.config ファイルです。2 番目の .config ファイルはビジネス ロジック DLL に固定する必要がありますが、最初のファイルは対応する UI 実行可能ファイルに固定する必要があります (独自の構成を持つ UI がもう 1 つ存在します)。

app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>

  <enterpriseLibrary.ConfigurationSource selectedSource="Winter DAL Configuration">
    <sources>
      <add name="Winter DAL Configuration" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        filePath="dll.config" />
    </sources>
  </enterpriseLibrary.ConfigurationSource> 
</configuration>

dll.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
  <dataConfiguration defaultDatabase="WinterContext" />
  <connectionStrings>
    <add name="WinterContext" connectionString="Data Source=Winter.sdf"
      providerName="System.Data.SqlServerCe.4.0" />
  </connectionStrings>
</configuration>

今、アプリを起動すると、DbContext は、指定された名前の接続文字列が見つからないという例外をスローします。接続文字列を dll.config から app.config に移動すると、すべて正常に動作します。

どうにかして構成を明示的にロードする必要があるのでしょうか? または?.. 私は何を間違っていますか?

事前にt​​hx!

4

2 に答える 2

3

提供された構成ファイルに基づいて、Entity Framework は開始プロジェクトのルートの app.config を調べましたが、EF コンテンツが見つかりませんでした。特に接続文字列。最初に UF を使用したとき、おそらくモデル プロジェクトにそのようなエントリが作成されます。IM は EF5.0 を使用しているため、Entity Section のカット アンド ペーストには注意してください。

<configuration>
 <configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
 <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
   <parameters>
     <parameter value="v11.0" />
   </parameters>
 </defaultConnectionFactory>
</entityFramework>
<connectionStrings>

<add name="CONTEXT_NAME_HERE"
     providerName="System.Data.SqlClient"
     connectionString="Data Source=YOURDB_SERVER;Initial Catalog=YOUR_DBNAME;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework" />

</connectionStrings>
</configuration>
于 2012-11-30T11:13:10.070 に答える