我需要在 ASP.NET Core 3.0 中使用代码优先创建一个数据库
这是DbContext:
public class TrelloContext : DbContext
{
public TrelloContext(DbContextOptions options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.AddDbSet<IEntity>(typeof(IEntity).Assembly);
modelBuilder.ApplyConfigurationsFromAssembly(typeof(IType).Assembly);
}
}
这是启动:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers().AddControllersAsServices();
services.AddDbContext<TrelloContext>(options => options.UseSqlServer(Configuration.GetConnectionString("SqlServer")));
services.Injection();
}
这是我的连接字符串:
"ConnectionStrings": {
"SqlServer": "Data Source=.;Initial Catalog=TrelloDB;Trusted_Connection=True;Trusted_Connection=True;"
}
当我使用这个时add-migration initial,我收到此错误:
值不能为空。(参数“键”)
有什么问题?我该如何解决这个问题?
料青山看我应如是
米脂