[英]Migration System.InvalidOperationException using EF MySQL
I'm trying to perform a first EF migration of database, but I get this exception:我正在尝试执行数据库的第一次 EF 迁移,但出现此异常:
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我在 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我正在使用 jetbrains Rider(但也不适用于 Visual Studio 2022)和这个 nuget 数据包: mysql.entityframeworkcore/6.0.1和microsoft.entityframeworkcore.design/6.0.1
The command line I used was: dotnet ef migrations AddInitialMigration我使用的命令行是: 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!
请帮我!
I discovered by myself a resolution for that problem.我自己发现了解决该问题的方法。 Creating a DbContext by Command Line to MySQL database connection, I finally get a migration:
通过命令行创建一个 DbContext 到 MySQL 数据库连接,我终于得到了一个迁移:
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.
谢谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.