首页 > 代码库 > 【转】使用EF CodeFirst 同时访问MySql和SqlServer配置

【转】使用EF CodeFirst 同时访问MySql和SqlServer配置

项目中的实际需求,需要写一个小工具将原来的sqlserver旧数据库定时导入到新系统中mysql数据库中。

1、EF实体文件生成就不说了,没什么需要注意的地方

2、引用技术分享

 

3、配置文件

<connectionStrings>
    <!--Mysql-->
    <add name="StatisticContext" connectionString="Data Source=192.168.1.233;port=3306;Initial Catalog=statistic2016;user id=root;password=root;" providerName="MySql.Data.MySqlClient" />
    <!--SqlServer-->
    <add name="DJG_RESModel" connectionString="data source=192.168.1.218;initial catalog=RES_DJG;persist security info=True;user id=sa;password=root-001;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.SqlClient" />
  </connectionStrings>

 

 

 

4、驱动配置 

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

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <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.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
    </providers>
  </entityFramework>

<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.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>

 

原文地址:

https://my.oschina.net/ligenhua/blog/824043?nocache=1493803818033

 

【转】使用EF CodeFirst 同时访问MySql和SqlServer配置