RelationshipManager.GetRelatedReference<TTargetEntity> Method (String, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets the EntityReference<TEntity> for a related object by using the specified combination of relationship name and target role name.

Namespace:   System.Data.Objects.DataClasses
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public EntityReference<TTargetEntity> GetRelatedReference<TTargetEntity>(
	string relationshipName,
	string targetRoleName
where TTargetEntity : class


Type: System.String

Name of the relationship to navigate. The relationship name is not namespace qualified.

Type: System.String

Name of the target role for the navigation. Indicates the direction of navigation across the relationship.

Return Value

Type: System.Data.Objects.DataClasses.EntityReference<TTargetEntity>

The EntityReference<TEntity> of a related object.

Type Parameters


The type of the returned EntityReference<TEntity>.

Exception Condition

The specified role returned an EntityCollection<TEntity> instead of an EntityReference<TEntity>.

The relationship name should not be namespace qualified. An error occurs when you prepend the namespace to the relationship name.

.NET Framework
Available since 3.5
Return to top