2017-01-09 50 views
1

私はtutoriel here(フランス語)に従っていますが、WCFアプリケーションをテストしているときにこの通信エラーが発生しています。 WcfTestClientを使用します。不変の名前 'MySql.Data.MySqlClient'を持つADO.NETプロバイダのエンティティフレームワークプロバイダが見つかりません - WCF

不変の名前 'MySql.Data.MySqlClient'を持つADO.NETプロバイダーのEntity Frameworkプロバイダーが見つかりません。プロバイダがアプリケーション設定 ファイルの 'entityFramework'セクションに登録されている であることを確認してください。

私はEntity FrameworkのライブラリプロジェクトとWcfSelfHostingのプロジェクトを1つ持っています。

エラーがここに来ている:

public IEnumerable<student> GetAllStudentsOfCourseFinance() 
{ 
    return SchoolDataEntities.enrollements.Where(t => t.course.title == "Finance").Select(t => t.student); 
} 

マイApp.configファイルをライブラリに

<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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/> 
    <providers> 
     <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/> 
    </providers> 
    </entityFramework> 
</configuration> 

WcfSelfHostingプロジェクトでの私のApp.config

<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
    </startup> 
    <connectionStrings> 
    <add name="schooldataEntities" connectionString="metadata=res://*/Data.Model.csdl|res://*/Data.Model.ssdl|res://*/Data.Model.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=localhost;user id=root;password=password;database=schooldata&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="BasicTextBinding" messageEncoding="Text" textEncoding="utf-8"> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="WCFExampleLibrary.WCFServices.SchoolWCFService"> 
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicTextBinding" contract="WCFExampleLibrary.WCFServices.ISchoolWCFService"> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8733/WCFExampleLibrary.WCFServices/SchoolWCFService/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    </system.serviceModel> 
</configuration> 

私はEntityframeworkとを追加しましたWcfSelfHostingプロジェクトのMySQL.Data.Entity.EF6参照。

+0

EF用のMysqlライブラリをインストールしていないと思いますか?それは可能性が? –

+0

はい、私は、MySQL.Data、MySQL.Data.Entity.EF6とMySQL.Web – Cantinou

答えて

2

私はあなたがエンティティフレームワークを使用する場合はDbContext.Ifから継承ApplicationContextのクラスを持っている必要があり、これは、あなたがこのようなApplicationContextのクラスに注釈を追加する必要がある場合であるとします

using System.Data.Entity; 

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] 
public abstract class ApplicationContext : DbContext 
{ 
    //Instructions......... 
} 

ます。また、編集することができますこのようなentityframeworkタグでweb.configファイル:

<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6"> 

は、必ず、このリンクを参照することができます:

http://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html

+0

私はすでにそれを試みた。また、entityframeworkタグを追加すると、「System.ServiceModel.Diagnostics.TraceUtilityの型初期化子が例外をスローしました」というサービスを開始するときにこのエラーが発生します。 "構成システムの初期化に失敗しました" – Cantinou

+0

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]を追加したときに動作しました。ありがとうございました! – Cantinou

+0

ようこそ。 – Younz301

関連する問題