1.下载3个包EntityFramework,mysql.data,mysql.data.entity
项目默认连接数据库是sqlserver,下载以上三个包后App.config会添加一条provider
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.10.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
</provider>
版本要注意 特别是后两个,后面两个我的版本都统一是6.10.8,版本不对有时会出现The provider did not return a ProviderManifestToken string等问题
其中invariantName 会和数据库的连接字符串有关
2.在app.config写入连接字符串
<connectionStrings>
<add name="FirstCodeFirstApp" connectionString="Data Source=localhost;port=3306;Initial Catalog=EfMysql;user id=root;password=123456;" providerName="MySql.Data.MyS