I'm trying to add a new user to the database using the following code:
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(); } }
But it keeps giving me the following error:
System.TypeLoadException: > Method 'Create' in type 'MySql.Data.EntityFrameworkCore.Query.Internal.MySQLSqlTranslatedExpressionVisitorFactory' in assembly 'MySql.Data.EntityFrameworkCore', version=8.0.22.0, culture=medium Properties, >PublicKeyToken=c5687fc88969c44d ' is not implemented. at MySql.Data.EntityFrameworkCore.Extensions.MySQLServiceCollectionExtensions.AddEntityFrameworkMySQL(IServ>iceCollection service) at MySql.Data.EntityFrameworkCore.Infrastruct.Internal.MySQLOptionsExtension.ApplyServices(IServiceColle>ction service) at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices(IDbContextOptions > Options, ServiceCollection Services) at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.
c__DisplayClass4_0.b__2(Int64 k) In 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.get_InternalServiceProvider() at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependency() 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) In D:devcontatinapiDataSeedData.cs at contatinApi.Data.SeedData.SeedUsers(): line 24 at System.Threading.Tasks.Task.<>c.b__139_1(ObjectState) at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi) at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext >executionContext, Action`1 callback, TState& state) in System.Threading.QueueUserWorkItemCallback.Execute() in System.Threading.ThreadPoolWorkQueue.Dispatch() In System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
User class:
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 and MySQL packages have been updated. Also, I tried using a stored procedure and it gave the same result.
The content ofEx is:
Ex value is {System.TypeLoadException: Method 'Create' in type 'MySql.Data.EntityFrameworkCore.Query.Internal.MySQLSqlTranslatedExpressionVisitorFactory' in assembly 'MySql.Data.EntityFrameworkCore', version=8.0.22.0, culture =neutral, PublicKeyToken=c5687fc88969c44d' is not implemented. at MySql.Data.EntityFrameworkCore.Extensions.MySQLServiceCollectionExtensions.AddEntityFrameworkMySQL(IServiceCollection service) at MySql.Data.EntityFrameworkCore.Infrastruct.Internal.MySQLOptionsExtension.ApplyServices(IServiceCollection service) at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.ApplyServices(IDbContextOptions options, ServiceCollection service) at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.g__BuildServiceProvider|3() at Microsoft.EntityFrameworkCore.Internal.ServiceProviderCache.<>c__DisplayClass4_0.b__2(Int64 k) In 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.get_InternalServiceProvider() at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependency() at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Internal.IDbContextDependency.get_StateManager() at Microsoft.EntityFrameworkCore.Internal.InternalDbSet1.EntryWithoutDetectChanges(TEntity entity) at Microsoft.EntityFrameworkCore.Internal.InternalDbSet
1.Add(TEntity entity) In D:devContatinApiDataSeedData.cs at contatinApi.Data.SeedData.SeedUsers(): line 40}
P粉5786806752023-10-23 10:01:31
If you are using Microsoft.EntityFrameworkCore 5.0, please downgrade it to Microsoft.EntityFrameworkCore 3.1.10 MySQL EF 8.0.22 is currently incompatible with Microsoft.EntityFrameworkCore 5.0
I had a working code until I upgraded to Microsoft.EntityFrameworkCore 5.0, then I got the same error, downgraded and it worked!
Hope to post a bug report on the MySQL Bug Forum