As from the previous question from here
I am willing update these data as:
employeeTable: FirstName, LastName
departmentTable: departmentName
workingshift: duration
However, now I try to modify my department_id
it comes out error said:
The property 'department_id' is part of the object's key information and cannot be modified.
Here is my query for joining data:
var result = (from e in DSE.employees
join d in DSE.departments on e.department_id equals d.department_id
join ws in DSE.workingshifts on e.shift_id equals ws.shift_id
Secondly, here is my coding for trying to modify the department_id
var result = (from e in DSE.employees
join d in DSE.departments on e.department_id equals d.department_id
join ws in DSE.workingshifts on e.shift_id equals ws.shift_id
where d.department_id == 1
select d).FirstOrDefault();
if (result != null)
{
result.department_id = 2;
DSE.SaveChanges();
}
Requirement:
- My ServicesEntities is DSE
- I am using Entities Framework
- My
department_id
is the joined object, same goes to myshift_id
- My `department_id' is not an auto increment id
Database Attributes:
Employee Table has employee_id, FirstName, LastName, Gender, Salary
Department Table has department_id, department_name
WorkingShift Table has shift_id, duration
Question:
Lets say I would like to update data as follows:
Employee FirstName = Stack, LastName = Overflow,
Department department id = 4, Department Name = Web,
Shift Shift_id = 2,
What coding should I perform as above session?