EF6 CodeFirst My [Key] Id Column is not auto-incrementing as an identity column should

后端 未结 2 1025
星月不相逢
星月不相逢 2020-12-31 04:25

I have several classes that I need to derive from a common base class which holds an Id. Ignoring the all but one of these for the moment, let\'s say we have:



        
2条回答
  •  渐次进展
    2020-12-31 04:55

    I remember when I used to do EF I would create a table with Identity and in the class I would attribute the id column with

    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    

    so I am assuming that your code should be

       modelBuilder.Entity()
            .Property(c => c.Id)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
    

提交回复
热议问题