How to tell Entity Framework that my ID column is auto-incremented (AspNet Core 2.0 + PostgreSQL)?

前端 未结 3 2108
生来不讨喜
生来不讨喜 2021-02-07 06:52

Code is simple. Tag.cs entity:

public partial class Tag
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { ge         


        
3条回答
  •  醉酒成梦
    2021-02-07 07:22

    According to the Postgre SQL docs here is an example which shows how to achieve the desired result:

    protected override void OnModelCreating(ModelBuilder modelBuilder)
       => modelBuilder.Entity().Property(b => b.Id).UseIdentityAlwaysColumn();
    

提交回复
热议问题