【问题标题】:No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' - WCF找不到具有不变名称“MySql.Data.MySqlClient”的 ADO.NET 提供程序的实体框架提供程序 - WCF
【发布时间】: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=&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>

我在 WcfSelfHosting 项目中添加了 Entityframework 和 MySQL.Data.Entity.EF6 引用。

【问题讨论】:

  • 我认为您还没有为 EF 安装 Mysql 库?可以吗?
  • 是的,我做到了,MySQL.Data、MySQL.Data.Entity.EF6 和 MySQL.Web

标签: c# mysql entity-framework wcf


【解决方案1】:

我想如果你使用实体框架,你必须有一个继承自 DbContext 的 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

【讨论】:

  • 我已经试过了。当我添加 entityframework 标记时,在启动服务时出现此错误“'System.ServiceModel.Diagnostics.TraceUtility' 的类型初始化程序引发了异常。” "配置系统初始化失败"
  • 当我添加 [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] 时它起作用了,谢谢!!
猜你喜欢
  • 2014-02-06
  • 2013-08-29
  • 2013-11-18
  • 1970-01-01
  • 1970-01-01
  • 2014-03-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多