未找到具有不变名称'MySql.Data.MySqlClient'的ADO.NET提供程序的实体框架提供程序-WCF [英] No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' - WCF
问题描述
我在此处(法语)中关注老师,但是我当我使用WcfTestClient测试WCF应用程序时,会出现此公共错误.
I am following the tutoriel here (in french) but I have this commun error coming when I am testing my WCF application with WcfTestClient.
没有为ADO.NET提供程序找到任何实体框架提供程序,其中 不变名称'MySql.Data.MySqlClient'.确保提供者是 已在应用程序配置的"entityFramework"部分中注册 文件.
No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file.
我有一个用于实体框架的图书馆项目,一个用于WcfSelfHosting的项目.
I have one Library project for Entity Framework and one project for the WcfSelfHosting.
错误来了:
public IEnumerable<student> GetAllStudentsOfCourseFinance()
{
return SchoolDataEntities.enrollements.Where(t => t.course.title == "Finance").Select(t => t.student);
}
我在库中的App.config
My App.config in the Library
<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
My App.config in WcfSelfHosting project
<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引用.
I added the Entityframework and MySQL.Data.Entity.EF6 references in the WcfSelfHosting project.
推荐答案
我想如果您使用实体框架,则必须具有从DbContext继承的ApplicationContext类.如果是这种情况,则需要在ApplicationContext类上添加注释,例如这个:
I suppose if you use entity framework you must have an ApplicationContext class inheriting from DbContext.If this is the case you need to add an annotation on the ApplicationContext class like this:
using System.Data.Entity;
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public abstract class ApplicationContext : DbContext
{
//Instructions.........
}
您也可以像这样在entityframework标签上编辑Web.Config文件:
You can also edit your Web.Config file at the entityframework tag like this :
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
您总是可以参考此链接:
You can always refer to this link :
http://dev.mysql.com /doc/connector-net/zh-CN/connector-net-entityframework60.html
这篇关于未找到具有不变名称'MySql.Data.MySqlClient'的ADO.NET提供程序的实体框架提供程序-WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!