builder.Services.AddDbContext<DEM_MASTERSContext>(options => options.UseSQLserver(builder.Configuration.GetConnectionString("Database")));
how to add connection string for pgadmin 4 , above one is for sqlserver
CodePudding user response:
for postgres you can add like this
services.AddDbContext<PostgreSqlContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("Database")));
For more you can follow this or this
CodePudding user response:
pgadmin4
is not a database, Do you want to ask how to connect to PostgreSQL?
First, you need to add NuGet package:
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
Then, you need to add connectionstring
in appsettings.json
:
{
"ConnectionStrings": {
"WebApiDatabase": "Host=localhost; Database=xxx; Username=xxx; Password=xxx"
},
}
Finally configure it like this:
services.AddDbContext<xxxContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("ConnectionStrings")));