I am having some trouble with refreshing the related collection of entities.
Essentially the problem is as follows:
public class Student
{
public virtual ICollection<Lecture> Lectures { get; set; }
public void AddLecture(Lecture lecture)
{
Lectures.Add(lecture);
}
public void CancelChanges()
{
_context.Refresh(RefreshMode.StoreWins, this);
_context.LoadProperty(this, (o) => o.Lectures,
MergeOption.OverwriteChanges);
}
}
public class Grade
{
public virtual Student { get; set; }
}
Now I have some GUI for adding lectures and, if we want we can cancel the editing process:
public void ExampleEdit()
{
Student student = _context.Students.SingleOrDefault(/* blah */);
student.AddLecture(_context.Lectures.SingleOrDefault(/* e.g. math */));
student.CancelChanges();
// At this point student SHOULD have no lectures anymore since the
// property was loaded with overwrite changes option.
// Yet the Lectures still contains the lecture we added there
}
So, is the code bad? Is there any method I use incorrectly? Is it possible to COMPLETELY reload the whole object?..