EF切换到Mysql数据库,更改web.config
1)引用:
MySql.Data.dll,MySql.Data.Entity.dll,MySql.Data.Entity.EF6.dll
2)添加:
<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>
3)更改数据库连接字符串:
<connectionStrings>
<!--<add name="WechatServiceContext" connectionString="Data Source=.\ms2008;Initial Catalog=Shares;Persist Security Info=True;User ID=sa;Password=sasasa;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>-->
<add name="WechatServiceContext" connectionString="Data Source=127.0.0.1;port=3306;Initial Catalog=shares;user id=root;password=root;Charset=utf8" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
4)增加
<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>