Home > DeveloperSection > Forums > How to create a primary key in ASP.NET MVC 4 using code first approach
Anupam Mishra

Total Post:135

Points:949
Posted on    February-02-2016 10:15 PM

 C# C#  ASP.Net  ASP.NET MVC 
Ratings:


 1 Reply(s)
 297  View(s)
Rate this:
Hi Everyone,
I have creating a model in ASP.NET  MVC using code first  approach but i am unable to creating  a primary key in a model.
Please can anyone give me a solution.
Thank you.


Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    February-02-2016 11:05 PM

Hi Anupam,
For creating a primary key you used the DataAnnotations. Similar as follow:
  public class Students
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

Don't want to miss updates? Please click the below button!

Follow MindStick