How to generate Identity value( from code behind ) in the database when a row is inserted in Asp.Net MVC ?

Posted by Goud.Kv under ASP.NET MVC category on | Points: 40 | Views : 1670
Below code snippet describes the generation of Identity value in the database from code behind in MVC.

Just modify your property in the Model as below,

public class myModel {
public int AutoId { get; set; }

'DatabaseGeneratedAttribute' is used to generate the Identity value automatically into the database.

'[Key]' mentioned above is used to define the primary key of the table.

Comments or Responses

Login to post response