我正在按照此处列出的MySql教程学习实体框架:https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
我已经通过NuGet在我的项目中安装了:
-实体框架v6.2.0
-MySql.Data.Entity v6.10.7
及其对应的依赖项。
我已经安装了MySql CONNECTOR / NET v8.0.11。
我将提供程序和connectionString添加到App.config:
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<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.10.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</providers>
</entityFramework>
<connectionStrings>
<add name="mysql" connectionString="Server=localhost,3306;Database=eneagramas;Uid=root;Pwd=1234;" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
我基本上遵循了官方文档中的所有说明,这是我的上下文类:
class MyContext : DbContext
{
public MyContext() : base("mysql")
{
//nothing here
}
public DbSet<Humans> Humans { get; set; }
}
但是访问数据库时出现此错误:
System.Data.Entity.Core.ProviderIncompatibleException
HResult=0x80131501
Message=The provider did not return a ProviderManifestToken string.
Source=EntityFramework
StackTrace:[...]
Inner Exception 1:
MethodAccessException: Attempt by method 'MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(System.Data.Common.DbConnection)' to access method 'MySql.Data.MySqlClient.MySqlConnection.get_Settings()' failed.
答案 0 :(得分:2)
您不能在MySql.Data 6.10.7中使用MySql.Data.Entity 8.0.11;主要版本不兼容。
针对v8的Oracle renamed the package至MySql.Data.EntityFramework。卸载MySql.Data.Entity并改为安装MySql.Data.EntityFramework。