Answer: The attribute in the Model field for the Identity column of the database should be DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity) like below
[Key]
[DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
[Required]
public int CategoryId { get; set; }
Thanks
Asked In: Many Interviews |
Alert Moderator