I am working on a project where I am using Entity framework to manipulate a DB on sql server 2014. My code is the following:
private void BtnAddUser(object sender, EventArgs e)
{
var u = new User();
u.username = txtBoxNewUser.Text;
u.password = txtBoxNewPass.Text;
u.rank = cmbBoxRank.GetItemText(this.cmbBoxRank.SelectedItem);
using (var db = new ProjetPooEntities2())
{
db.Users.Add(u);
db.SaveChanges();
}
}
Please note that the code runs perfectly but it when i press the Add button to add the created user to the db an error shows on "db.saveChanges()" and it says:
System.Data.Entity.Infrastructure.DbUpdateException: 'An error occurred while updating the entries. See the inner exception for details.' And the inner exception is: SqlException: Cannot insert explicit value for identity column in table 'User' when IDENTITY_INSERT is set to OFF.
I have set the identity column in the db to "id" and it is set to auto-increment by 1 starting from 1. I have tried searching a lot for a solution but i found nothing. Any help will be appreciated!!