提供者未返回ProviderManifestToken字符串

提供者未返回ProviderManifestToken字符串

本文介绍了“提供者未返回ProviderManifestToken字符串"具有实体框架的MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS 2017中建立了一个新项目.我的意图是使用EF CodeFirst方法.到目前为止,我使用了Azure SQL数据库,而在此测试项目中,我想使用远程MySQL数据库.我已经创建了用户,权限设置恰到好处.我可以通过MySQL Workbench访问此远程数据库服务器.

I have set up a new project in VS 2017. My intention is to use EF CodeFirst approach. So far I used Azure SQL Database, while in this test project I want to use my remote MySQL database. I have created the user and permissions are set just right. This remote database server is accessible to me over MySQL Workbench.

我创建了一个新的空白MVC项目,并通过Nuget安装了MySQL.Data.Entity(版本6.9.10).

I have created a new blank MVC project and through Nuget I installed MySQL.Data.Entity (version 6.9.10).

我的上下文类:

[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class WebDb : DbContext
{
    public WebDb() : base("WebDb")
    {

    }

    public DbSet<Candidate> Candidates { get; set; }
}

我的web.config具有以下条目:

My web.config has these entries:

<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.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
    </providers>
  </entityFramework>
  <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.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>

我的连接字符串是:

<connectionStrings>
    <add name="WebDb" providerName="MySql.Data.MySqlClient" connectionString="server=x.x.x.x;uid=dbuser;pwd=password;database=temp1;" />
</connectionStrings>

我有一个简单的域类

public class Candidate
{
    public int Id { get; set; }
    public string Name { get; set; }
}

当我给出Enable-Migrations -Force命令时,我得到了

When I give Enable-Migrations -Force command, I get

据我所知,我已经进行了广泛搜索,但无济于事.这里发生了什么事?我想念什么?

I have searched far and wide to the best of my knowledge to no avail. What's happening here? What am I missing?

推荐答案

我最近遇到了与您相同的问题.在SQL Server中一切正常,但是在转换为MySQL时遇到很多问题.对我有用的一些东西是:

I've been having the same problems as you recently. Everything worked fine in SQL Server, but I was having lots of problems converting to MySQL. Some things that worked for me are:

    Install-Package MySQL.Data -Version 6.9.9
    Install-Package MySql.Data.Entity -Version 6.9.10

MySQL的较新的8.0软件包似乎有问题.当我恢复到旧版本时,它起作用了.

The newer 8.0 packages of MySQL appear to have problems. When I reverted to an older version, it worked.

您的app.config应该如下所示:

Your app.config should look like:

      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <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.8.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
    </providers>
  </entityFramework>
  <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.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
      <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>
</configuration>

即使在那之后,我还是发现MySQL中存在一些差异.例如,您的迁移索引"语句将不起作用.您必须编辑迁移文件并自己构建索引.我刚刚读过但尚未遇到的另一件事是,MySQL驱动程序不允许多个连接,这可能意味着更改了检索异步集合的方式.最后,我对RowVersion是byte []有问题.我使用了以下文章的一种变体来解决此问题(希望如此!).

Even after that, there are some discrepancies in MySQL that I'm just finding out. For example, your migration "index" statements will not work. You'll have to edit the migration file and build the index yourself. Another thing that I just read, but haven't encountered, is that the MySQL driver does not allow multiple connections which may mean changing the way you retrieve async collections. Lastly, I had a problem with RowVersion being a byte[]. I used a variation from the following article to solve this (hopefully!).

实现带有EF Core和MySQL的行版本?

这篇关于“提供者未返回ProviderManifestToken字符串"具有实体框架的MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 15:46