Entity Framework 核心添加迁移给出的值不能为空。 dotnet 中的(参数 'connectionString')
Entity Framework Core Add Migration gives Value cannot be null. (Parameter 'connectionString') in dotnet
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"AuthConnectionString": "Server=.;Database=EmployeeLeaveDatabase;Trusted_Connection=True"
}
这里请检查
builder.Services.AddDbContext<AuthDbContext>(options => options.UseSqlServer(
builder.Configuration.GetConnectionString("AuthConnectionString")));
builder.Services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<AuthDbContext>();
我正在尝试添加迁移,但不知道为什么会出现此错误
System.ArgumentNullException: 值不能为空。 (参数'connectionString')
在 Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(字符串值,字符串参数名称)
在 Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuilder,String connectionString,Action`1 sqlServerOptionsAction)
在 Program.<>c__DisplayClass0_0.<$>b__0(DbContextOptionsBuilder options) 在 C:\Users\Seventhball\source\repos\EmployeeLeaveManagement\EmployeeLeaveManagement\Program.cs:line 9
如果这样定义:
"AuthConnectionString": "Server=.;Database=EmployeeLeaveDatabase;Trusted_Connection=True"
使用这个:
builder.Configuration.GetValue<string>("AuthConnectionString")
如果这样定义:
"ConnectionStrings": { "AuthConnectionString": "Server=.;Database=EmployeeLeaveDatabase;Trusted_Connection=True;"}
使用这个:
builder.Configuration.GetConnectionString("AuthConnectionString")
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"AuthConnectionString": "Server=.;Database=EmployeeLeaveDatabase;Trusted_Connection=True"
}
这里请检查
builder.Services.AddDbContext<AuthDbContext>(options => options.UseSqlServer(
builder.Configuration.GetConnectionString("AuthConnectionString")));
builder.Services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<AuthDbContext>();
我正在尝试添加迁移,但不知道为什么会出现此错误 System.ArgumentNullException: 值不能为空。 (参数'connectionString') 在 Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(字符串值,字符串参数名称) 在 Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(DbContextOptionsBuilder optionsBuilder,String connectionString,Action`1 sqlServerOptionsAction) 在 Program.<>c__DisplayClass0_0.<$>b__0(DbContextOptionsBuilder options) 在 C:\Users\Seventhball\source\repos\EmployeeLeaveManagement\EmployeeLeaveManagement\Program.cs:line 9
如果这样定义:
"AuthConnectionString": "Server=.;Database=EmployeeLeaveDatabase;Trusted_Connection=True"
使用这个:
builder.Configuration.GetValue<string>("AuthConnectionString")
如果这样定义:
"ConnectionStrings": { "AuthConnectionString": "Server=.;Database=EmployeeLeaveDatabase;Trusted_Connection=True;"}
使用这个:
builder.Configuration.GetConnectionString("AuthConnectionString")