无法添加迁移:system.invalidoperationException:无法解析类型的服务' Microsoft.entityframeworkcore.dbcontextoptions'

发布于 2025-02-12 17:30:03 字数 1982 浏览 1 评论 0 原文

尝试为我的.NET Core 6.0项目添加迁移时,我会收到以下错误: 在类“程序”上没有找到静态方法“ Create -HostBuilder(String [])'。 找不到应用服务提供商。 在项目中查找DBContext类... 找到dbContext'applicationdbContext'。 Microsoft.EntityFrameWorkCore.Design.OperationException:无法创建类型“ ApplicationDbContext”的对象。有关设计时间支持的不同模式,请参见 https://go.microsoft.com/microsoft.com/fwlink /?linkID = 851728 ---> system.invalidoperationException:无法解析“ Microsoft.entityFrameWorkCore.dbContextOptions”类型的服务,同时尝试激活'dataAccess.data.applicationdbcontext'。

我的项目结构看起来像这样: 在此处输入图像描述

使用我的dataAcess项目,包含我的代码第一个结构,我的applicationdbcontext代码是:

    public class ApplicationDbContext : IdentityDbContext<IdentityUser>
{
    public ApplicationDbContext(DbContextOptions options)
    : base(options)
    {
    }

    public ApplicationDbContext() { }


    public DbSet<Attachment> Attachments { get; set; }
    public DbSet<Column> Columns { get; set; }
    public DbSet<DevopsBoard> DevopsBoards { get; set; }
    public DbSet<DevopsBug> DevopsBugs { get; set; }
    public DbSet<Priority> Priorities { get; set; }
    public DbSet<Project> Projects { get; set; }
    public DbSet<Severity> Severities { get; set; }

}

i在EF CLI中尝试了以下选项: 添加迁移第一个-startupproject dataAccess -verbose

add -Orgration首先-Project issuemaster -startupproject dataAccess -Verbose

可以给我一些指导吗?

我已经尝试了以下方面的尝试:

When attempting to add a migration for my .net core 6.0 project, I get the following error:
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'ApplicationDbContext'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions' while attempting to activate 'DataAccess.Data.ApplicationDbContext'.

My project structure looks like this:
enter image description here

with my dataacess project containing my code first structure, my ApplicationDbContext code is:

    public class ApplicationDbContext : IdentityDbContext<IdentityUser>
{
    public ApplicationDbContext(DbContextOptions options)
    : base(options)
    {
    }

    public ApplicationDbContext() { }


    public DbSet<Attachment> Attachments { get; set; }
    public DbSet<Column> Columns { get; set; }
    public DbSet<DevopsBoard> DevopsBoards { get; set; }
    public DbSet<DevopsBug> DevopsBugs { get; set; }
    public DbSet<Priority> Priorities { get; set; }
    public DbSet<Project> Projects { get; set; }
    public DbSet<Severity> Severities { get; set; }

}

I have tried the following options in the EF cli:
add-migration first -startupproject dataaccess -verbose

add-migration first -Project issuemaster -startupproject dataaccess -verbose

Can anybody give me some guidance?

I have tried the stuff on: 'Unable to resolve service for type ¨Microsoft.entityFrameworkCore.DbContextOptions¨1[LibraryData.LibraryContext] while attempting to activate

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

傲鸠 2025-02-19 17:30:03

对我的情况有用的是,我已将Microsoft.EntityFrameWorkCore.Design添加到我的启动项目和Microsoft.entityframeworkcore, *工具和 *sqlserver和 *SQLServer中

,并且在运行迁移之后

What worked for my case is that I've added Microsoft.EntityFrameworkCore.Design for my startup project and Microsoft.EntityFrameworkCore, *Tool, and *SqlServer have been installed into the Infrastructure project

and after that run the migration

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