Migration System.InvalidoperationException使用EF MySQL

发布于 2025-02-02 23:34:41 字数 1245 浏览 5 评论 0原文

我正在尝试执行数据库的第一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心是晴朗的。 2025-02-09 23:34:41

我自己发现了这个问题的解决方案。通过命令行创建一个DBContext到MySQL数据库连接,我终于得到一个迁移:

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

我现在要关注问题。谢谢大家。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文