1,Nuget中安装库
Microsoft.EntityFrameworkCore.tools
Npgsql.EntityFrameworkCore.PostgreSQL
2,数据表Model文件
public class Test
{
[Key]
[Column("id")]
public Guid? ID { get; set; }
[Column("newname")]
public string NewName { get; set; }
}
3,数据库上下文
public class test_Context:DbContext
{
public DbSet<Test> Test { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionBuilder)
{
optionBuilder.UseNpgsql("Host=xxxxxx;Username=xxxx;Password=xxxxx;Database=xxxxx");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
4,"工具" ——> "NuGet程序管理器"——>"程序包管理控制台"
enable-migrations
add-migration
update-database
表结构建立在用户public中