I am trying to insert a new record into
tblUser and also update a record in
tblEmployee at the same time. The new record in
tblUser saves fine, but the update part of second table is not working. The complier reads
tbEmp.IsUser = true; this line though. What am I missing.
public void Save(tblUser objUser)
{
MYDB.AddTotblUsers(objUser);
tblEmployee tbEmp = this.GetEmployeeRecordById(objUser.EmpId);
if(tbEmp!=null)
{
string abc = tbEmp.EmployeeCode;
tbEmp.IsUser = true;
}
MYDB.SaveChanges();
}
public tblEmployee GetEmployeeRecordById(Guid gId)
{
return MYDB.tblEmployees.Where(e=>e.EmployeeId == gId).SingleOrDefault();
}
The
EmpId is known already and is not necessary that
tblUser has to Save First before updating
tblEmployee . To make sure, I checked 'abc', I get that employees code there...