The idea behind lazy loading is that the entity framework loads only the information that you have attempted to access. Consider the following:
using (MyContext context = new MyContext())
{
User myUser = context.Users.First();
}
In this example, only the User
object is loaded. None of the related entities are retrieved from the database until they are first accessed.
using (MyContext context = new MyContext())
{
User myUser = context.Users.First(); // User is loaded from database
Profile myProfile = myUser.Profile; // Associated profile is loaded
}
In the second example, there are two database calls - one to load the User, and a second to load the Profile when it is first accessed.
All three types of relationships (one-to-one, one-to-many, many-to-many) have this same behavior: related objects are not loaded until first access.