Guest User

Guest User

  • Tech Writer
  • 515
  • 42.5k

About Identity-Auto Increment Id in MVC

Feb 6 2021 6:44 PM
Hello everyone,
Hope everyone is fine 
 
I am working on web application using OrmLite and Sql server.
I have created table "AgeGroups" with column "id" as PrimaryKey and Set Identity to True in Sql table, So that I can achieve autoincrement in my web application
 
But in application when I am trying to insert record it always gets "id" as 0 and don't auto increment
 
In my entity I have already used [Key] and  Identity attribute to id column. Following is my table

public partial class age_groups
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public string name { get; set; }
public DateTime created_at { get; set; }
public DateTime updated_at { get; set; }
}
 
I tried to use [AutoIncrement] attribute, but it says 'could not find assembly', so I am not sure which dll I am missing.
 
Also, Please help to save AutoIncrement Id in sql database, Any help  will be appreciated.
 
Thank you in advance 
 

Answers (9)