简体   繁体   English

EF5 核心更新数据库错误无法创建类型为“ApplicationDbContext”的 object

[英]EF5 Core Update database Error Unable to create an object of type 'ApplicationDbContext'

I want a migration of my database, I was able to create the migration but the update database command does not pass我想要迁移我的数据库,我能够创建迁移但更新数据库命令没有通过

项目

DI DI

services.AddDbContext<ApplicationDbContext>(options =>
         options.UseSqlServer(Configuration.GetConnectionString("TravelCS")
         ));

  services.AddScoped<IApplicationDbContext>(provider => provider.GetService<ApplicationDbContext>());

Interface IApplicationDbContext:接口 IApplicationDbContext:

    DbSet<TourList> TourLists { get; set; }
DbSet<TourPackage> TourPackages { get; set; }

Task<int> SaveChangesAsync(CancellationToken cancellationToken);

AppDbContext AppDb上下文

  public class ApplicationDbContext : DbContext, IApplicationDbContext
  {
    private readonly IDateTime _dateTime;
    private IDbContextTransaction _currentTransaction;

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

    public DbSet<TourList> TourLists { get; set; }
    public DbSet<TourPackage> TourPackages { get; set; }

    public ApplicationDbContext(
      DbContextOptions<ApplicationDbContext> options,
      IDateTime dateTime) : base(options)
    {
      _dateTime = dateTime;
    }

AppDbContext 类

错误控制台

Resolved解决

Resolved by using update-database instead of dt.net ef update-database Oo通过使用 update-database 而不是 dt.net ef update-database Oo 解决

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法创建“ApplicationDbContext”类型的 object。 英核5.0 - Unable to create an object of type 'ApplicationDbContext'. Ef core 5.0 错误“无法创建类型为 &#39;ApplicationDbContext&#39; 的对象。” - Error "Unable to create an object of type 'ApplicationDbContext'." 无法在 asp .net 核心 5 中创建类型为“ApplicationDbContext”的 object - Unable to create an object of type 'ApplicationDbContext' in asp .net core 5 无法创建类型为“ApplicationDbContext”的对象。 添加 &#39;IDesignTimeDbContextFactory 的实现<ApplicationDbContext> &#39; 到项目 - Unable to create an object of type 'ApplicationDbContext'. Add an implementation of 'IDesignTimeDbContextFactory<ApplicationDbContext>' to the project EF Core 迁移与 SQLite 数据库:无法创建 object 类型 - EF Core migration with SQLite database: unable to create object of type 无法创建“applicationdbcontext”类型的 object。 对于设计时支持的不同模式错误 - unable to create an object of type 'applicationdbcontext'. For the different patterns supported at design time error 无法创建“ApplicationDbContext”类型的 object。 对于设计时支持的不同模式 - Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time Sqlite 和 WPF 中的 EF Core 播种数据与关系 model - 无法创建类型为 DbContext 错误的 object - EF Core seeding data in Sqlite and WPF with relational model - unable to create an object of type DbContext error 无法使用现有数据库运行EF5迁移 - Unable to run EF5 migration with existing database 使用 dotnet ef 错误迁移:无法创建“MyClass”类型的对象 - Migration with dotnet ef error: Unable to create an object of type 'MyClass'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM