![](/img/trans.png)
[英]Identity in ASP.NET Core (2.1): Why do we need to add a new Context to customize IdentityUser?
[英]ASP.NET Core : Why do we need IDesignTimeDbContextFactory?
我有一个 ASP.NET 核心应用程序,我只有DataContext
,我没有实现IDesignTimeDbContextFactory
。
public class DataContext : DbContext, IUnitOfWork
{...}
有了它,我可以做Add-Migration
、 Update-Database
和Script-Migration
。
但是,我遇到了另一个他们已经实现IDesignTimeDbContextFactory
的项目,提到这是为了生成迁移类。
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<CodingBlastDbContext>
{
public CodingBlastDbContext CreateDbContext(string[] args)
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
var builder = new DbContextOptionsBuilder<CodingBlastDbContext>();
var connectionString = configuration.GetConnectionString("DefaultConnection");
builder.UseSqlServer(connectionString);
return new CodingBlastDbContext(builder.Options);
}
}
我想知道为什么需要这个? 特别是第一个项目没有实现IDesignTimeDbContextFactory
..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.