What should be the attribute for a Model property that corresponds to the Identity column of the database?

 Posted by Sheonarayan on 11/14/2013 | Category: ASP.NET MVC Interview questions | Views: 4648 | Points: 40
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 

Comments or Responses

Login to post response