Navigation Properties

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

Navigation properties in the Entity Framework provide a way to navigate an association between two entity types. A navigation property is defined by the NavigationProperty Element (CSDL) in the conceptual model. Every object can have a navigation property for every relationship in which it participates. Navigation properties allow you to navigate and manage relationships in both directions, returning either an EntityReference, if the multiplicity is either one or zero-or-one, or an EntityCollection, if the multiplicity is many. You may also choose to have one-way navigation, in which case you can delete the navigation property, for more information, see How to: Edit and Delete Navigation Properties

When you use the Entity Framework-generated classes, navigation properties are created for objects that participate in a relationship. For information on working with navigation properties in POCO entities, see Requirements for Creating POCO Proxies.

Modifying Relationships

You can use navigation properties to change a relationship. The following example assigns a different customer to an order by using the Customer navigation property on the Order object to access the customer reference that is associated with that order: order.Customer = customer.

The following example adds an order to an existing customer order by using the Orders navigation property to access the collection of orders that belong to the customer:


In a foreign key association, you can form or change a relationship by setting the foreign key property of the dependent object, as in the following example:

order.CustomerID = CustomerID.

For more information about independent and foreign key associations, see Defining and Managing Relationships.

You can use navigation properties to load objects that are related to an entity by the defined association. For more information, see Loading Related Objects and How to: Navigate Relationships Using Navigation Properties.

Navigating Relationships

The following example in method-based query syntax uses the SelectMany method to get all the orders of the contacts whose last name is "Zhou". The Contact.SalesOrderHeader navigation property is used to get the collection of SalesOrderHeader objects for each contact.

See Also