I have following structure in EF for Users.
- Users - This will hold all the users (Standard as well as Supervisor Users).
- Supervisors - This will hold only Supervisors
- UserToSupervisors - This will hold mapping of both. A supervisor can have multiple standard members.
Now if new supervisor is added. i first add it to the Supervisor table, and then in the UserToSupervisor table with navigational properties like below.
userDo.Supervisor = new Supervisor { Id = userDo.Id, Type = "GROUP LEADER" };
Then i add it to the mapping table like below:
userDo.Supervisor.UserToSupervisors.Add(new UserToSupervisor
{
UserId = userDo.Id,
SupervisorId = GetSelectedGroupLeaderId
});
and finally i call userDao.Add(userDo)
Now on Saving changes to database, the user is created, also supervisor is fine. However in UserToSupervisor table it adds UserId and SupervisorId both of the Current user, although it should add SupervisorId of the Supervisor from GetSelectedGroupLeaderId.
During Debugging i verified the GetSelectedGroupLeaderId is populated with proper SupervisorId.
But during SaveChanges call, it changes to current userid. I doubt that's because i am first calling userDo.Supervisor and assinging current user. but that's required since the current user is a supervisor user and not standard user.
Can anyone suggest what's wrong with my above code?