Let’s say you have a class object:
public class Class
{
IList<Student> students;
}
And you have a student object:
public class Student
{
private Class class;
}
When loading these objects from the database, what is the best way to load the association?
When you load a class, you will have an empty list of students. If you load students first, you will have a null reference to the class object until the classes are loaded.
If you’re using an ORM, just let the lazy loading feature handle it. Just be aware of the select n + 1 problem.
If you’re not using an ORM, start using an ORM.