Can't auto-generate IDENTITY with AddRange in Entity Framework

后端 未结 4 1525

I don\'t know if it\'s an Entity Framework\'s desing choice or a wrong approach on my behalf, but whenever I try to AddRange entities to a DbSet I can\'t seem to get the aut

4条回答
  •  时光说笑
    2021-01-07 22:15

    Please try this, it works for Int type column, need to try on long types.

    [Table("entities")]
    public class Entity 
    {
        [Key]
        [Column("id")]
        // this you need to tell to Ef to use Identity .
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long Id { get; set; }
    
        [Column("field")]
        public string Field { get; set; }
    }
    

提交回复
热议问题