Skip to main content
added screenshot
Source Link
Stephen__T
  • 2k
  • 3
  • 25
  • 49

I'm pretty sure this is a simple configuration error but my lack of experience is prohibiting me from fixing it. Basically I want to add an EMPLOYEE to a table using entity frame work.

Here is my method:

 public void createEmployee(CreateEmployeeModel model) { EMPLOYEE emp = new EMPLOYEE() { emp_name = model.Name, emp_email = model.Email, emp_cell_phone = model.CellPhone, emp_adr = model.Address }; _db.AddToEMPLOYEES(emp); _db.SaveChanges(); } 

I get the following error on the _db.SaveChanges(); call: Cannot insert duplicate key row in object 'dbo.EMPLOYEES' with unique index 'R18_SDE_ROWID_UK'. The duplicate key value is (0).

Here is the emp_id column properties for the EMPLOYEE Entity:

StoreGeneratedPattern : Identity Concurrency Mode : None Default Value : (None) Entity Key : True Name: emp_id Nullable: False Type : Int32 

Here is the emp_id column properties for the EMPLOYEES Table on SQL server:

Name : emp_id Data Type : int Primary Key: True Allow Nulls: False Is Computed: False Identity : True Identity Seed : 1 Identity Increment : 1 

enter image description here

I'm not sure why the primary key is always being generated as a 0 when there is already 4 employees in the table. (0,1,2,3).

I'm pretty sure this is a simple configuration error but my lack of experience is prohibiting me from fixing it. Basically I want to add an EMPLOYEE to a table using entity frame work.

Here is my method:

 public void createEmployee(CreateEmployeeModel model) { EMPLOYEE emp = new EMPLOYEE() { emp_name = model.Name, emp_email = model.Email, emp_cell_phone = model.CellPhone, emp_adr = model.Address }; _db.AddToEMPLOYEES(emp); _db.SaveChanges(); } 

I get the following error on the _db.SaveChanges(); call: Cannot insert duplicate key row in object 'dbo.EMPLOYEES' with unique index 'R18_SDE_ROWID_UK'. The duplicate key value is (0).

Here is the emp_id column properties for the EMPLOYEE Entity:

StoreGeneratedPattern : Identity Concurrency Mode : None Default Value : (None) Entity Key : True Name: emp_id Nullable: False Type : Int32 

Here is the emp_id column properties for the EMPLOYEES Table on SQL server:

Name : emp_id Data Type : int Primary Key: True Allow Nulls: False Is Computed: False Identity : True Identity Seed : 1 Identity Increment : 1 

I'm not sure why the primary key is always being generated as a 0 when there is already 4 employees in the table. (0,1,2,3).

I'm pretty sure this is a simple configuration error but my lack of experience is prohibiting me from fixing it. Basically I want to add an EMPLOYEE to a table using entity frame work.

Here is my method:

 public void createEmployee(CreateEmployeeModel model) { EMPLOYEE emp = new EMPLOYEE() { emp_name = model.Name, emp_email = model.Email, emp_cell_phone = model.CellPhone, emp_adr = model.Address }; _db.AddToEMPLOYEES(emp); _db.SaveChanges(); } 

I get the following error on the _db.SaveChanges(); call: Cannot insert duplicate key row in object 'dbo.EMPLOYEES' with unique index 'R18_SDE_ROWID_UK'. The duplicate key value is (0).

Here is the emp_id column properties for the EMPLOYEE Entity:

StoreGeneratedPattern : Identity Concurrency Mode : None Default Value : (None) Entity Key : True Name: emp_id Nullable: False Type : Int32 

Here is the emp_id column properties for the EMPLOYEES Table on SQL server:

enter image description here

I'm not sure why the primary key is always being generated as a 0 when there is already 4 employees in the table. (0,1,2,3).

Source Link
Stephen__T
  • 2k
  • 3
  • 25
  • 49

Why won't Entity Framework let SQL server generate a primary key?

I'm pretty sure this is a simple configuration error but my lack of experience is prohibiting me from fixing it. Basically I want to add an EMPLOYEE to a table using entity frame work.

Here is my method:

 public void createEmployee(CreateEmployeeModel model) { EMPLOYEE emp = new EMPLOYEE() { emp_name = model.Name, emp_email = model.Email, emp_cell_phone = model.CellPhone, emp_adr = model.Address }; _db.AddToEMPLOYEES(emp); _db.SaveChanges(); } 

I get the following error on the _db.SaveChanges(); call: Cannot insert duplicate key row in object 'dbo.EMPLOYEES' with unique index 'R18_SDE_ROWID_UK'. The duplicate key value is (0).

Here is the emp_id column properties for the EMPLOYEE Entity:

StoreGeneratedPattern : Identity Concurrency Mode : None Default Value : (None) Entity Key : True Name: emp_id Nullable: False Type : Int32 

Here is the emp_id column properties for the EMPLOYEES Table on SQL server:

Name : emp_id Data Type : int Primary Key: True Allow Nulls: False Is Computed: False Identity : True Identity Seed : 1 Identity Increment : 1 

I'm not sure why the primary key is always being generated as a 0 when there is already 4 employees in the table. (0,1,2,3).