【发布时间】:2021-11-09 01:03:05
【问题描述】:
如前所述,我必须配置两个数据库,即 MSSQL 和 MYSQL。对于 MSSQL 案例,它可以工作,但现在我必须添加新数据库(MySQL),但在下面遇到这个问题
The type 'MySql.Data.MySqlClient.MySqlConfiguration' does not inherit from 'System.Data.Entity.DbConfiguration'.
Entity Framework code-based configuration classes must inherit from 'System.Data.Entity.DbConfiguration'.
对于我的 app.config
<?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>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-8.0.26.0" newVersion="8.0.26.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"></remove>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=8.0.26.0" />
</DbProviderFactories>
</system.data>
</configuration>
【问题讨论】:
-
您可能需要这些程序集:dev.mysql.com/doc/connector-net/en/…
-
@GHDevOps 我想我已经添加了程序集但仍然抛出这个错误。
-
web.config 中的 dbConfiguration 在哪里?你必须告诉 EF 使用什么配置。
标签: c# mysql entity-framework