Why is EF trying to insert NULL in id-column?

前端 未结 9 2090
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 00:43

I am writing my project using Entity Framework 4.0 (Model first). At the beginning of the project, I faced with this problem: I am trying to insert the filled object in the

9条回答
  •  伪装坚强ぢ
    2020-12-10 01:23

    Try to add this into your model class .cs file:

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int CategoryId { get; set; }
    

    Or change your column CategoryId to identity:

        CategoryId int IDENTITY(1,1)
    

提交回复
热议问题