繁体   English   中英

如何在 asp.net mvc 核心的 program.cs 中添加 pgadmin db

[英]How to add pgadmin db in program.cs in asp.net mvc core

builder.Services.AddDbContext<DEM_MASTERSContext>(options => options.UseSQLserver(builder.Configuration.GetConnectionString("Database")));

如何为pgadmin 4添加连接字符串,上面一个是用于sqlserver的

对于 postgres,您可以像这样添加

services.AddDbContext<PostgreSqlContext>(options =>
        options.UseNpgsql(Configuration.GetConnectionString("Database")));

有关更多信息,您可以关注

pgadmin4不是数据库,请问如何连接PostgreSQL?

首先,您需要添加 NuGet package:

dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL

然后,您需要在appsettings.json中添加connectionstring字符串:

{
    "ConnectionStrings": {
        "WebApiDatabase": "Host=localhost; Database=xxx; Username=xxx; Password=xxx"
    },
}

最后配置如下:

services.AddDbContext<xxxContext>(options =>
        options.UseNpgsql(Configuration.GetConnectionString("ConnectionStrings")));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM