appsetting.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"ConnectionString": "server=localhost;Database=FakeXieChengDb;User Id=sa;Password=123"
}
}
配置Program文件
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
//获取配置字符串
var connectionString = builder.Configuration.GetConnectionString("ConnectionString");
builder.Services.AddControllers();
//添加上下文呢服务
builder.Services.AddDbContext<APPDbContext>(option =>
{
option.UseSqlServer(connectionString);
});
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.MapControllers();
app.Run();
}
标签:Core,ConnectionString,app,EF,字符串,var,NET,builder From: https://www.cnblogs.com/budongdong/p/16774972.html