Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于MySQL的Enity框架_Mysql_Entity Framework - Fatal编程技术网

基于MySQL的Enity框架

基于MySQL的Enity框架,mysql,entity-framework,Mysql,Entity Framework,我得到以下错误 无法加载在ADO.NET提供程序的应用程序配置文件中注册的实体框架提供程序类型“MySql.Data.MySqlClient.MySqlProviderServices,MySql.Data.Entity”,该提供程序的固定名称为“MySql.Data.MySqlClient”。确保使用了程序集限定名称,并且运行的应用程序可以使用该程序集。有关详细信息,请参阅。” 然而,我的项目中引用了MySql.Data.dll和MySql.Data.Entity.dll以及MySql.Dat

我得到以下错误

无法加载在ADO.NET提供程序的应用程序配置文件中注册的实体框架提供程序类型“MySql.Data.MySqlClient.MySqlProviderServices,MySql.Data.Entity”,该提供程序的固定名称为“MySql.Data.MySqlClient”。确保使用了程序集限定名称,并且运行的应用程序可以使用该程序集。有关详细信息,请参阅。”

然而,我的项目中引用了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>


我的完整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>

对于面临相同问题的任何人,下面是导致异常的一行

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

只需将.EF6附加到MySql.Data.Entity,这样提供程序如下

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


因此,您选择删除中的代码无助于解决问题。我希望这对其他人有所帮助。

您也可以执行以下操作

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

检查内部异常

我明白了

{”类型违反的继承安全规则:
“MySql.Data.Entity.MySqlEFConfiguration”。派生类型必须为
与基类型的安全性可访问性匹配或更少
可访问。“:“MySql.Data.Entity.MySqlEFConfiguration”}

这让我想到:


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

你能补充一些关于更改内容的说明吗?什么是“DbConfigurationType?”"? 在VS.@StealthRabbi中,它不是建议的导入,它位于
MySql.Data.EntityFramework
命名空间上。在Connector.NET 8.0中,引用的文件现在是
MySql.Data.EntityFramework.dll
,因此您可能必须使用
MySql.Data.Entity.EF6
。新文件仍被认为是框架6。
[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class DemoContext : DbContext{}
{