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

Total Post:135

Points:949
C#
 810  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. 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; }

      Modified On Apr-11-2018 01:17:29 AM

Answer

NEWSLETTER

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