尝试在与Pomelo.EntityFrameworkCore.MySql相关的dotnet core 3.1中添加迁移时遇到错误

问题描述

当我收到此错误

dotnet ef migrations add InitialMigration

方法“创建”的类型 'Pomelo.EntityFrameworkCore.MysqL.Query.ExpressionVisitors.Internal.MysqLsqlTranslatingExpressionVisitorFactory' 来自程序集'Pomelo.EntityFrameworkCore.MysqL,Version = 3.2.3.0, 文化=中性,PublicKeyToken = 2cc498582444921b'没有 实施。

实体框架核心.NET命令行工具5.0.0-rc.2.20475.6

完全错误-

Build started...
Build succeeded.
System.TypeLoadException: Method 'Create' in type 'Pomelo.EntityFrameworkCore.MysqL.Query.ExpressionVisitors.Internal.MysqLsqlTranslatingExpressionVisitorFactory' from assembly 'Pomelo.EntityFrameworkCore.MysqL,Version=3.2.3.0,Culture=neutral,PublicKeyToken=2cc498582444921b' does not have an implementation.
   at Microsoft.Extensions.DependencyInjection.MysqLServiceCollectionExtensions.AddEntityFrameworkMysqL(IServiceCollection serviceCollection)    
   at Pomelo.EntityFrameworkCore.MysqL.Infrastructure.Internal.MysqLOptionsExtension.ApplyServices(IServiceCollection services)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices(IDbContextOptions options,ServiceCollection services)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__displayClass4_0.<GetorAdd>g__BuildServiceProvider|3()
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__displayClass4_0.<GetorAdd>b__2(Int64 k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetorAdd(TKey key,Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetorAdd(IDbContextOptions options,Boolean providerrequired)
   at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
   at Commander.Data.CommanderContext..ctor(DbContextOptions`1 opt) in D:\.NET\project02\data\CommanderContext.cs:line 8
--- End of stack trace from prevIoUs location where exception was thrown ---
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite,RuntimeResolverContext 
context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite,TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite,RuntimeResolverContext context,ServiceProviderEnginescope serviceProviderEngine,RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite,RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite,TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite,ServiceProviderEnginescope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__displayClass1_0.<RealizeService>b__0(ServiceProviderEnginescope scope) 
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType,ServiceProviderEnginescope serviceProviderEnginescope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEnginescope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider,Type type)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__displayClass13_3.<FindContextTypes>b__11()
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name,String outputDir,String contextType,String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name,String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__displayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__displayClass3_0`1.<Execute>b__0()
   at 

Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Method 'Create' in type 'Pomelo.EntityFrameworkCore.MysqL.Query.ExpressionVisitors.Internal.MysqLsqlTranslatingExpressionVisitorFactory' from assembly 'Pomelo.EntityFrameworkCore.MysqL,PublicKeyToken=2cc498582444921b' does not have an implementation.

依赖关系-

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <packagereference Include="Microsoft.EntityFrameworkCore" Version="5.0.0-rc.2.20475.6" />
    <packagereference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0-rc.2.20475.6">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </packagereference>
    <packagereference Include="Pomelo.EntityFrameworkCore.MysqL" Version="3.2.3" />
    <packagereference Include="Pomelo.EntityFrameworkCore.MysqL.Design" Version="1.1.2" />
  </ItemGroup>


</Project>

appsetting.js

 "ConnectionStrings": 
  {
    "DefaultConnection": "server=localhost;port=3306;database=CommanderDB;uid=root;password=ishanah"
  }

startup.cs-

  public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddDbContext<CommanderContext>(options =>
        options.UseMysqL(Configuration.GetConnectionString("DefaultConnection")));

            services.AddScoped<ICommanderRepo,MockCommanderRepo> ();
        }

解决方法

我已经解决了这个问题。 只需为 EF 核心和 Pomelo.EntityFrameworkCore.MySql 升级相同版本:5.x。 请注意,您应该在 5.0 alpha 1(而不是 alpha 2)版本中使用 Pomelo 以使启动文件正确运行。

,

3.2.3与EF Core 5不兼容(请参阅Compatibility)。当前,您需要使用nuget.orgnightly build feed中的alpha prerelease 来使用EF Core 5。

有关更多信息,请查看EF Core 5 Preview support

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...