1,使用.netcore框架建立两个项目

asp.netcore连接postgres数据库 codefirst

2,在model项目建立数据表实体类

asp.netcore连接postgres数据库 codefirst

3,在model中添加数据库上下文

asp.netcore连接postgres数据库 codefirst

4,在codefirt项目中的appsettings.json中条件连接字符串

 "ConnectionStrings": {
    "DefaultConnection": "Host=xxx;Username=xxx;Password=xxx;Database=xxx" 
  }

5,在codefirst的startup中添加

asp.netcore连接postgres数据库 codefirst

6,"工具" ——> "NuGet程序管理器"——>"程序包管理控制台"

默认项目选择model
 add-migration 

update-database

相关文章: