I would propose that you create
a method, RefreshStudentCourses, or
something like that, and then call
it at strategic points throughout
your application.
I hear you, but that will result in a lot of more methods. For example,
my Course object can have a lot of other collection properties
- Students
- Assigments
- Chairs
- Desks
- TeachingAssistants
- Exams
- Handouts
So are you suggesting a method for every one of those? Surely you don't
want one RefreshFromDataBase() to refresh all of them in one swoop,
because that will make a lot unnecessary trips to all of them only the
only thing you are interested in is, say, Exams.
I would rather do this when I use Students in case you need to retain
it.
students = course.Students;
//at this point, students does not get refreshed
//any more and I can do whatever I want.
Console.Write(students.Count); //no trip to database
Console.Write(course.Students.Count); //a refresh from database