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

Total Post:135

Points:949

C#
 1103  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. 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

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.