HOW TO CREATE A PRIMARY KEY IN ASP.NET MVC 4 USING CODE FIRST APPROACH

Anupam Mishra

Total Post:135

Points:949
Posted by  Anupam Mishra
C#
 552  View(s)
Ratings:
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.
  1. Manoj Bhatt

    Post:154

    Points:1086
    Re: How to create a primary key in ASP.NET MVC 4 using code first approach

    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; }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!