一尘不染

使用MySQL的Enity框架

mysql

我收到以下错误

“在ADO.NET提供程序的应用程序配置文件中注册的实体框架提供程序类型’MySql.Data.MySqlClient.MySqlProviderServices,MySql.Data.Entity’,其不变名称为’MySql.Data.MySqlClient’。无法加载。确保请确保使用了程序集限定名称,并且该程序集可用于正在运行的应用程序。有关更多信息,请参见http://go.microsoft.com/fwlink/?LinkId=260882

但是我确实在我的项目中引用了MySql.Data.dll和MySql.Data.Entity.dll以及MySql.Data.Entity.EF6.dll(来自MySQL
Connector Net 6.8.3)

这是我的App.conf

<?xml version="1.0" encoding="utf-8"?>
 <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>
 <connectionStrings>
  <add name="inspectm_inspectContext" connectionString="server=--user id=--;password=--;database=--;persistsecurityinfo=True" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
<system.data>
  <DbProviderFactories>
    <add name="MySQL Data Provider"
    invariant="MySql.Data.MySqlClient"
    description=".Net Framework Data Provider for MySQL"
    type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
<providers>
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity" />
</providers>
</entityFramework>
</configuration>

阅读 314

收藏
2020-05-17

共1个答案

一尘不染

<?xml version="1.0" encoding="utf-8"?>
<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>
  <connectionStrings>
    <add name="inspectm_inspectContext" connectionString="server=--;user id=--;password=--;database=--;persistsecurityinfo=True" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
     <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
     </providers>
  </entityFramework>
</configuration>

我的Complete App.conf对我有用

首先我删除了

<DbProviderFactories>
<add name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>

然后我改变了

<defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />

并添加了提供者

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
2020-05-17