Auto-increment on partial primary key with Entity Framework Core

后端 未结 5 2056
野趣味
野趣味 2020-12-13 05:50

I have declared the following model using the EF Core fluent API:

modelBuilder.Entity()
    .HasKey(p => new { p.Name, p.Id });
5条回答
  •  庸人自扰
    2020-12-13 06:17

    Specifying the column type as serial for PostgreSQL to generate the id.

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    [Column(Order=1, TypeName="serial")]
    public int ID { get; set; }
    

    https://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL

提交回复
热议问题