gpt4 book ai didi

c# - System.TypeLoadException : Method 'Create' in type 'MySql.Data.EntityFrameworkCore.Query.Internal.MySQLSqlTranslatingExpressionVisitorFactory'

转载 作者:行者123 更新时间:2023-12-04 11:18:11 44 4
gpt4 key购买 nike

我正在尝试使用以下代码向数据库添加一个新用户:

public async void SeedUsers(){
int count=0;
if(count>0){
return;
}
else{
string email="jujusafadinha@outlook.com.br";
_context.Add(new User{LoginEmail=email});
await _context.SaveChangesAsync();
}
}
但它不断给我以下错误:

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(IServ>iceCollection services)at MySql.Data.EntityFrameworkCore.Infrastructure.Internal.MySQLOptionsExtension.ApplyServices(IServiceColle>ction services)at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices(IDbContextOptions >options, ServiceCollection services)at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<c__DisplayClass4_0.g__BuildServiceProvider|3()at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.b__2(Int64 k)at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, >Boolean providerRequired)at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()at Microsoft.EntityFrameworkCore.DbContext.EntryWithoutDetectChanges[TEntity](TEntity entity)at Microsoft.EntityFrameworkCore.DbContext.SetEntityState[TEntity](TEntity entity, EntityState >entityState)at Microsoft.EntityFrameworkCore.DbContext.Add[TEntity](TEntity entity)at contatinApi.Data.SeedData.SeedUsers() in D:\dev\contatinapi\Data\SeedData.cs:line 24at System.Threading.Tasks.Task.<>c.b__139_1(Object state)at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi)at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext >executionContext, Action`1 callback, TState& state)at System.Threading.QueueUserWorkItemCallback.Execute()at System.Threading.ThreadPoolWorkQueue.Dispatch()at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()


用户类:
public class User
{
public int Id{get;set;}
public string LoginEmail{get;set;}
public string UserName{get;set;}
public DateTime CreatedAt{get;set;}
public List<Contact> Contacts {get;set;}
public List<ContactList> ContactLists{get;set;}
}
EF Core 和 MySQL 包均已更新。此外,我尝试使用存储过程,它给出了相同的结果。
Ex的内容是:

The value of Ex was {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.<>c__DisplayClass4_0.g__BuildServiceProvider|3()at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.b__2(Int64 k)at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.GetOrAdd(IDbContextOptions options, Boolean providerRequired)at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependencies.get_StateManager()at Microsoft.EntityFrameworkCore.Internal.InternalDbSet1.EntryWithoutDetectChanges(TEntity entity) at Microsoft.EntityFrameworkCore.Internal.InternalDbSet1.Add(TEntity entity)at contatinApi.Data.SeedData.SeedUsers() in D:\dev\ContatinApi\Data\SeedData.cs:line 40}

最佳答案

如果您使用的是 Microsoft.EntityFrameworkCore 5.0,请将其降级到 Microsoft.EntityFrameworkCore 3.1.10 MySQL EF 8.0.22 目前与 Microsoft.EntityFrameworkCore 5.0 不兼容
我有一个工作代码,直到我升级到 Microsoft.EntityFrameworkCore 5.0 然后我得到了同样的错误,降级并且它工作了!
希望在 MySQL Bug 论坛上发布 Bug 报告

关于c# - System.TypeLoadException : Method 'Create' in type 'MySql.Data.EntityFrameworkCore.Query.Internal.MySQLSqlTranslatingExpressionVisitorFactory' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64614651/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com