c# entity framework 访问mysql数据库

1、项目TOOLS -> Manage NuGet Packages -> 搜索框输入:MySql.Data -> 搜索
   即出来了
   MySql.Data            Install
   MySql.Data.Entity     Install
   备注文件会生成相应配置信息:
   <connectionStrings>
     <add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=connect;user id=root;password=000000;" providerName="MySql.Data.MySqlClient"/>
   </connectionStrings>


  <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.8.0, Culture=neutral, 


PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <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.Entity.EF6, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
      </provider>
    </providers>
  </entityFramework>
</configuration>


注意:千万别手动引用dll,手动修改配置文件,容易出错。

你可能感兴趣的:(c# entity framework 访问mysql数据库)