【发布时间】:2017-01-09 09:20:19
【问题描述】:
我正在关注教程 here(法语),但是当我使用 WcfTestClient 测试我的 WCF 应用程序时出现此常见错误。
找不到 ADO.NET 提供程序的实体框架提供程序 不变的名称'MySql.Data.MySqlClient'。确保提供者是 在应用程序配置的“entityFramework”部分注册 文件。
我有一个用于实体框架的库项目和一个用于 WcfSelfHosting 的项目。
错误来了:
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="server=localhost;user id=root;password=password;database=schooldata"" 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>
我在 WcfSelfHosting 项目中添加了 Entityframework 和 MySQL.Data.Entity.EF6 引用。
【问题讨论】:
-
我认为您还没有为 EF 安装 Mysql 库?可以吗?
-
是的,我做到了,MySQL.Data、MySQL.Data.Entity.EF6 和 MySQL.Web
标签: c# mysql entity-framework wcf