How to: Explicitly Load Related Objects
This topic provides examples of how to explicitly load related objects.
The first example uses the Load method on EntityCollection to explicitly load all orders and items for a single customer. The Load method cannot be used with POCO entities because the navigation properties of POCO entities are not required to return EntityCollection. For more information, see Loading Related POCO Entities.
The second example uses the CreateSourceQuery method to create a query that loads only selected orders with the related items. These orders are then attached to the customer.
The following example loads SalesOrderHeader objects that belong to a single Contact and then iterates through the SalesOrderHeader objects in the EntityCollection. On each SalesOrderHeader object in the collection, the Load method is called to retrieve the collection of related SalesOrderDetail objects from the database.
The following example uses the CreateSourceQuery method on the EntityCollection to only load five SalesOrderHeader objects, with related SalesOrderDetail objects, that belong to a single Contact. This query result is then attached to the original SalesOrderHeader EntityCollection.