Yes you are correct about the defaults. You can customize the behavior in a few ways as well: In the model (depending on provider) you can set lazy-loading properties to fetch at the time the main object is fetched, or to wait until that particular property is requested (default).
Also, you can load one EntitySet per parent per query in a query with DataLoadOptions
, example:
public class Parent
{
public string Name { get; set; }
public EntitySet<Child> Children { get; set; }
}
public class Child
{
public string Name { get; set; }
public int Age { get; set; }
}
var dlo = new DataLoadOptions();
dlo.LoadWith<Parent>(p => p.Children);
var dc = new DataContext();
dc.LoadOptions = dlo;
var parentAndChildren = from p in dc.Parents select p;
The above would perform a left join to fetch the children in a single query. You can find more examples in the DataLoadOptions
MSDN Docs. There's also a similar AssociateWith
for restricted loading you may want to check out.
Also, if you need to load the EntitySet earlier, you can call .Load() on it.