How to configure an Identity column using Entity Framework Core?

前端 未结 5 736
借酒劲吻你
借酒劲吻你 2021-01-03 19:10

How do I create an Auto increment identity column in Entity Framework Core?

Obviously I can do it using fluent API for EF6 for example.

5条回答
  •  渐次进展
    2021-01-03 19:51

    In latest version of EF7 there is a new extension method to set identity column

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {    
      modelBuilder.Entity(b =>
      {
        b.HasKey(e => e.Identifier);
        b.Property(e => e.Identifier).ValueGeneratedOnAdd();
      });
    }
    

提交回复
热议问题