小编ema*_*man的帖子

无法创建类型为“ApplicationDbContext”的对象。对于设计时支持的不同模式

在 .net core 中添加数据库迁移时遇到以下错误

这是错误:

这是中的代码Startup

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>(options => 
    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
           
    services.AddDefaultIdentity<ApplicationUser>().AddEntityFrameworkStores<ApplicationDbContext>();
    services.AddControllers();
}
Run Code Online (Sandbox Code Playgroud)

这是ApplicationDbContext课程:

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

    public DbSet<ApplicationUser> applicationUsers { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是ApplicationUser

public class ApplicationUser : IdentityUser
{
    [Required]
    [Column(TypeName = "nvarchar(150)")]
    public string UserFName { get; set; }
    [Required]
    public string UserLName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

c# .net-core asp.net-core .net-core-3.0 .net-core-3.1

22
推荐指数
8
解决办法
2万
查看次数