Migration System.InvalidoperationException使用EF MySQL
我正在尝试执行数据库的第一个EF迁移,但是我得到了这个例外:
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage.TypeMappingSourceDependencies' while attempting to activate 'MySql.EntityFrameworkCore.Storage.Internal.MySQLTypeMappingSource'.
我在Imgur上添加了stacktrace: https://i.sstatic.net/yv7se.jpg
我正在使用Jetbrains Rider(但也不在Visual Studio 2022和此Nuget数据包工作: mysql.entityFrameWorkCore/6.0.1 和 Microsoft.entityFrameWorkCore.design/6.0.1
我使用的命令行是: dotnet ef迁移addinitialmigration
我的整个代码是:
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'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://i.sstatic.net/yv7Se.jpg
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己发现了这个问题的解决方案。通过命令行创建一个DBContext到MySQL数据库连接,我终于得到一个迁移:
我现在要关注问题。谢谢大家。
I discovered by myself a resolution for that problem. Creating a DbContext by Command Line to MySQL database connection, I finally get a migration:
I'm going to close question now. Thank you everyone.