首先在nuget里找到几个源如下
然后安装下来
现在讲的是先设计好数据库的方式postgre安装配置不多做介绍
现在数据库里建一张表如下
然后去建一个模型类对应表里的键值代码如下
public class User
{
public Guid ID { get; set; }
public string UserName { get; set; }
public int? Age { get; set; }
}
然后手动继承DBContext
public class EnergyIotDbContext : DbContext
{
public EnergyIotDbContext(DbContextOptions<EnergyIotDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
}
public virtual DbSet<User> User { get; set; }
}
<