I have this code (VS2010 ASP.NET MVC 3 with EF 4):
Project project = new Project();
project.Number = number;
project.Name = name;
context.AddObject(project);
ProjectUser projectUser = new ProjectUser();
projectUser.User = user;
projectUser.Status = 1;
project.ProjectUsers.Add(projectUser);
context.SaveChanges(true);
It generates the following error (in the line "project.ProjectUsers.Add (ProjectUser)")
"The relationship between two objects cannot be determined because they are bound to different ObjectContext objects."
I don’t understand why the reason, as far as I know, both objects use the same ObjectContext (but I am new to EF).
What am I doing wrong? Thank you for your help!
Canam source
share