ASP.NET + 使用Mysql作为数据库

  1. 下载Mysql for VisualStudiohttp://dev.mysql.com/downloads/windows/visualstudio/
  2. 下载连接器http://dev.mysql.com/downloads/connector/net/
  3. 使用Nuget安装EF。
  4. 使用Nuget安装Mysql.Data
  5. 修改web.config的connectionStrings连接字符串如下:
1
2
3
<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=服务器IP;port=3306;Initial Catalog=数据库名称;user id=用户名;password=密码;" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  1. 重要一定要在entityFramework节上增加codeConfigurationType=“MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6"属性。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <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>
Built with Hugo
主题 StackJimmy 设计