生成.NET 6中的模型迁移

huangapple go评论65阅读模式
英文:

Generate migration for models in .NET 6

问题

我创建了我的模型,并想要运行以下命令来创建我的迁移并通过命令创建表格:

dotnet ef migrations add InitialCreate

我收到以下错误消息:

System.TypeLoadException: 程序集 'MySql.Data.EntityFrameworkCore, Version=8.0.22.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' 中的类型 'MySql.Data.EntityFrameworkCore.Query.Internal.MySQLSqlTranslatingExpressionVisitorFactory' 的 'Create' 方法没有实现。

这些是我的已安装包:

[net6.0]: 
顶级包                        请求的版本    已解析版本
Microsoft.EntityFrameworkCore  7.0.5          7.0.5
Microsoft.EntityFrameworkCore.Design 7.0.5  7.0.5
MySql.Data.EntityFrameworkCore 8.0.22      8.0.22
Swashbuckle.AspNetCore       6.2.3          6.2.3

我该如何解决这个问题?

英文:

I created my models and I want to run this command to create my migrations and create the tables via command:

dotnet ef migrations add InitialCreate

I get this error:

> System.TypeLoadException: Method 'Create' in type 'MySql.Data.EntityFrameworkCore.Query.Internal.MySQLSqlTranslatingExpressionVisitorFactory' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.22.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.
>
> at MySql.Data.EntityFrameworkCore.Extensions.MySQLServiceCollectionExtensions.AddEntityFrameworkMySQL(IServiceCollection services)
> at MySql.Data.EntityFrameworkCore.Infrastructure.Internal.MySQLOptionsExtension.ApplyServices(IServiceCollection services)
> at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices(IDbContextOptions options, ServiceCollection services)
> at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<GetOrAdd>g__BuildServiceProvider|4_1(IDbContextOptions _, ValueTuple2 arguments)
&gt; at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.&lt;&gt;c.&lt;GetOrAdd&gt;b__4_0(IDbContextOptions contextOptions, ValueTuple
2 tuples)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd[TArg](TKey key, Func3 valueFactory, TArg factoryArgument)
at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)
at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
at snappfood_new_stack.Models.AppDbContext..ctor(DbContextOptions options) in /home/snappfood/RiderProjects/snappfood_new_stack/snappfood_new_stack/Models/AppDbContext.cs:line 7
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1&amp; arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
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 callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.&lt;&gt;c__DisplayClass2_0.&lt;RealizeService&gt;b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.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.&lt;&gt;c__DisplayClass21_3.&lt;FindContextTypes&gt;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 outputDir, String contextType, 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 'MySql.Data.EntityFrameworkCore.Query.Internal.MySQLSqlTranslatingExpressionVisitorFactory' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.22.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.

These are my installed packages:

[net6.0]:
Top-level Package Requested Resolved
Microsoft.EntityFrameworkCore 7.0.5 7.0.5
Microsoft.EntityFrameworkCore.Design 7.0.5 7.0.5
MySql.Data.EntityFrameworkCore 8.0.22 8.0.22
Swashbuckle.AspNetCore 6.2.3 6.2.3

How can I fix this?

答案1

得分: 1

尝试使用这个包替代:https://www.nuget.org/packages/MySql.EntityFrameworkCore/

MySql.Data.EntityFrameworkCore 已被弃用,详见此处

英文:

Try this package instead: https://www.nuget.org/packages/MySql.EntityFrameworkCore/

MySql.Data.EntityFrameworkCore has been depreciated as noted here.

huangapple
  • 本文由 发表于 2023年6月2日 05:21:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76385788.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定