带有 MySQL 的 Enity 框架

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21954207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:06:15  来源:igfitidea点击:

Enity Framework With MySQL

mysqlentity-framework

提问by Donald Jansen

I am getting the following error

我收到以下错误

"The Entity Framework provider type 'MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity' registered in the application config file for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882for more information."

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

However I do have MySql.Data.dll and MySql.Data.Entity.dll and also MySql.Data.Entity.EF6.dll referenced in my project (comes from MySQL Connector Net 6.8.3)

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

Here is my App.conf

这是我的 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>

采纳答案by Donald Jansen

<?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>

My Complete App.conf this worked for me

我的完整 App.conf 这对我有用

First I removed

首先我删除了

<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>

Then I changed

然后我变了

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

And Added the provider

并添加了提供者

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

回答by Dev

for anyone facing the same problem, here is the line that causes the Exception is this

对于任何面临同样问题的人,这里是导致异常的行是这样的

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity" />

Just append .EF6 to MySql.Data.Entity such that the provider is like this

只需将 .EF6 附加到 MySql.Data.Entity 这样提供程序就是这样

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />

As such your choice to remove the code within didn't help solve the problem. I hope this helps someone.

因此,您选择删除其中的代码并没有帮助解决问题。我希望这可以帮助别人。

回答by Kay Albertus

You Could Also Do the Following

您还可以执行以下操作

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class DemoContext : DbContext{}
{

回答by Dennis Robinson

Check for an inner exception.

检查内部异常。

I get

我得到

{"Inheritance security rules violated by type: 'MySql.Data.Entity.MySqlEFConfiguration'. Derived types must either match the security accessibility of the base type or be less accessible.":"MySql.Data.Entity.MySqlEFConfiguration"}

{"Inheritance security rules violated by type: 'MySql.Data.Entity.MySqlEFConfiguration'. Derived types must either match the security accessibility of the base type or be less accessible.":"MySql.Data.Entity.MySqlEFConfiguration"}

That points me to: Inheritance security rules violated by type: 'MySql.Data.Entity.MySqlEFConfiguration'

这指向我: 类型违反的继承安全规则:'MySql.Data.Entity.MySqlEFConfiguration'

I dont really like to downgrade. But so far i haven't found a better answer.

我真的不喜欢降级。但到目前为止,我还没有找到更好的答案。