c# - 如何解决实体框架中的 system.data 配置问题
问题描述
如果将我的项目更新为 mysql.data 8.0.13 和 MySql.Data.EntityFramework。目标框架是 .net 4.5.2 EF 在 6.2 我现在有一个奇怪的行为,我必须将 system.data 部分添加到我的配置中
<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" />
</DbProviderFactories>
</system.data>
然后它在一些机器上运行。但在其他人身上,你会得到以下错误。(翻译成英语,因为系统是德语)
System.Configuration.ConfigurationErrorsException: An error occurred when creating the configuration section handler for system.data: The column 'InvariantName' has the restriction that it must be unique. The value 'MySql.Data.MySqlClient' already exists.
所以如果我删掉这部分配置,它就可以工作。但在另一台机器上它说。
System.ArgumentException: The ADO.NET provider with the invariant name 'MySql.Data.MySqlClient' was either not registered on the computer or in the application configuration file, or could not be loaded.
有没有可能的解决方案或检查?因为我对同一台电脑上的不同用户也有奇怪的行为(通过 clickonce 推出)
EF的配置部分
<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.EntityFramework"></provider>
</providers>
</entityFramework>
这应该适用于任何电脑。我也不知道如何添加更多信息,因为我真的不知道问题出在哪里。整个周末都试图解决这个问题。
解决方案
我不太确定,但你可以试试这个:
从 System.data 元素:
添加这个:
<remove invariant="MySql.Data.MySqlClient" />
好像:
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<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.8.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
您可以包含该版本或删除您的版本。
但是,如果您包含该版本,请确保它是您正在使用的 MYSQL 版本。
推荐阅读
- pandas - 标题:以 mm/dd/yyyy 格式创建日期范围
- spring - Spring STS 3.9.7 跳过安装过程并打开工作区
- javascript - Javascript在特定时间更改文本阴影方向
- node.js - 为什么在使用 shelljs 克隆 git repo 时会出现 NullReferenceException?
- postgresql - PostgreSQL 10 => 11.1 关于 Brew 更新问题
- excel - Excel VBA 创建 Outlook 电子邮件规则以将传入邮件移动到特定文件夹
- csv - Microsoft SSIS - 将带有多个逗号 (,) 且没有双引号 (") 的平面文件 (.csv) 加载到 SQL Server 表中
- html - 更改布局时防止 CSS Fade
- python - 在 python 中读取文件:json.decoder.JSONDecodeError
- ios - 管理音频实例以允许交叉淡入淡出等的最佳策略