使用MySQL和MSSQL为Entity Framework提供两个不同的数据库

Jam*_*mes 5 mysql sql-server entity-framework

我正在尝试构建一个web api,它提供来自MySQL数据库或MSSQL数据库(完全不同的数据和模式)的数据.它还提供了一些在两者之间移动数据的端点.我已经创建了两个类库来保存两个数据库的EF模型,并且已成功连接到两个实例并针对两个实例运行查询.它倒下的地方是试图访问它们.我必须调整web.config entityFramework部分以使其工作,我无法得到它,以便两者有效地同时工作.我正在使用EF6和最新的MySQL连接器.

这是MSSQL实体的工作配置:

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="v11.0" />
  </parameters>
</defaultConnectionFactory>
<providers>
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
Run Code Online (Sandbox Code Playgroud)

这是我尝试使用MySQL实体上下文时产生的错误

The default DbConfiguration instance was used by the Entity Framework before the 'MySqlEFConfiguration' type was discovered. An instance of 'MySqlEFConfiguration' must be set at application start before using any Entity Framework features or must be registered in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=260883 for more information.
Run Code Online (Sandbox Code Playgroud)

这是MySQL实体的工作配置:

<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
  <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />  
Run Code Online (Sandbox Code Playgroud)

然后,这就是在尝试使用MySQL库时抱怨连接字符串.我在网上找不到这个问题,这个问题类似但是没有答案:是否有可能为MySql和SqlServer设置EF上下文?

有没有人这样做或知道解决问题的方法?

Jam*_*mes 1

在撰写本文时,该问题似乎已在 beta MySQL 连接器版本 6.9.1 中得到解决。我现在可以让两个人并排运行,没有任何问题。

更新

为了澄清起见,我的设置是 EF5(EF6 不起作用)和 MySQL 连接器版本 6.9.1(测试版)。我的 web.config 部分如下所示:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
Run Code Online (Sandbox Code Playgroud)

该模型位于同一个项目中,我再次在类库方面遇到了困难。