Export (0) Print
Expand All

How to: Query Related Objects in an EntityCollection

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This topic provides examples of how to query related objects in an EntityCollection returned by the relationship navigation property.

The example in this topic is based on the Adventure Works Sales Model. To run the code in this example, you must have already added the AdventureWorks Sales Model to your project and configured your project to use the Entity Framework. To do this, complete the procedures in How to: Manually Configure an Entity Framework Project and How to: Manually Define the Model and Mapping Files. You can also use the Entity Data Model Wizard to define the AdventureWorks Sales Model. For more information, see How to: Use the Entity Data Model Wizard.

Example

This example loads the collection of SalesOrderHeader objects related to a specific contact, and then uses a LINQ expression to return a list of orders placed online that have already shipped.

This example uses the same LINQ query as the first example against the collection of SalesOrderHeader objects. Instead of initially loading all related objects into the collection, the CreateSourceQuery method is used to load only the objects returned by the query. The Load method is then called on the EntityCollection returned by the SalesOrderHeader relationship navigation property to load the remaining related objects.

See Also

Show:
© 2015 Microsoft