I have MVC project and EF6 model.
LazyLoading is enabled. In controller I have the following action
public ActionResult AddStage(int projectId, int employeeId)
{
using(var context = new TestProjectEntities())
{
var project = context.Projects.Find(projectId);
if (project != null)
{
var stage = new Stage() {EmployeeID = employeeId, StageType = 1};
project.Stages.Add(stage);
context.Stages.Add(stage);
context.SaveChanges();
}
ListEmployees(project);
}
return Redirect("Index");
}
private void ListEmployees(Project project)
{
var names = new List<string>();
foreach(var stage in project.Stages)
{
if (stage.Employee != null)
{
names.Add(stage.Employee.Name);
}
}
}
But in ListEmployees method stage.Employee == null in foreach statement. Why?
And if i call AddStage for second time then stage.Employee != null in ListEmployee
