Migration System.InvalidOperationException using EF MySQL

Viewed 71

I'm trying to perform a first EF migration of database, but I get this exception:

System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage.TypeMappingSourceDependencies' while attempting to activate 'MySql.EntityFrameworkCore.Storage.Internal.MySQLTypeMappingSource'.

I upped stacktrace at imgur: https://imgur.com/a/OWnsas8

I'm using jetbrains rider (but isn't working at Visual Studio 2022 as well) and this nuget packets: mysql.entityframeworkcore/6.0.1 and microsoft.entityframeworkcore.design/6.0.1

The command line I used was: dotnet ef migrations AddInitialMigration

My entire code is:

namespace LibraryDB.db;
internal class CatalogueContext : DbContext
{
    public DbSet<Book> catalogue { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseMySQL("server=localhost;database=libraryDB2;user=username;password=password");
    }
}

##### 

namespace LibraryDB;
public class Book
{
   [Key]
   public string Name { get; set; }
   public string Publisher { get; set; }
}

I already searched over all internet, but i can't get a resolution for that. Please help-me!

1 Answers

I discovered by myself a resolution for that problem. Creating a DbContext by Command Line to MySQL database connection, I finally get a migration:

dotnet ef dbcontext scaffold "Server=localhost;User Id=youruser;Password=yourpassword;Database=yourdatabase" "Pomelo.EntityFrameworkCore.MySql" -c MyDbContext

I'm going to close question now. Thank you everyone.

Related