简体   繁体   中英

What is the correct pacakge versions to use MySQL in .NET 6.0 and EF Core?

I am trying to upgrade a .NET 5.0 API server project to .NET 6.0, and I have a csproj file like this:

...
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
      <GenerateDocumentationFile>true</GenerateDocumentationFile>
      <NoWarn>$(NoWarn);1591</NoWarn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BCrypt-Official" Version="0.1.109" />
    <PackageReference Include="CryptSharpOfficial" Version="2.1.0" />
    <PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.7" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
    <PackageReference Include="Microsoft.OpenApi" Version="1.2.3" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5" />
    <PackageReference Include="MongoDB.Driver" Version="2.13.1" />
    <PackageReference Include="MongoDB.Driver.Core" Version="2.13.1" />
    <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.22" />
    <PackageReference Include="MySql.EntityFrameworkCore" Version="5.0.8" />
    <PackageReference Include="MySqlConnector" Version="2.0.0" />
    <PackageReference Include="NLog" Version="4.7.12" />
    <PackageReference Include="NLog.Extensions.Logging" Version="1.7.4" />
    <PackageReference Include="NLog.Web.AspNetCore" Version="4.14.0" />
    <PackageReference Include="NUnit" Version="3.13.2" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
    <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.1" />
  </ItemGroup>
...

Then when I execute the code, I get exception:

System.TypeLoadException: 'Method 'AppendIdentityWhereCondition' in type 'MySql.EntityFrameworkCore.MySQLUpdateSqlGenerator' from assembly 'MySql.EntityFrameworkCore, Version=5.0.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.'

When I create a new DbContext. 构造函数异常

Also, there is another really big DbContext using old ways, I want to keep them working without modifying them.

It seems like I am using the wrong version of MySQL library, but I have no idea what am I doing wrong. How can I setup the MySQL connector correctly?

Use Pomelo for MySQL 6.0.0 instead just worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM