Get Related Entities

Example to get the list of emails associated to the Contact :

entity is the Contact entity
RelationShipName : Contact_Emails

public static IEnumerable GetRelatedEntitiesExtended(OrganizationServiceContext ctx, Entity entity, RelationShipName
relationshipShemaName) where T : Entity
{
ctx.MergeOption = MergeOption.NoTracking;
ctx.LoadProperty(entity, new Relationship(relationshipShemaName.ToString()));
//Microsoft.Xrm.Client for SKD 2015
return entity.GetRelatedEntities(relationshipShemaName.ToString());
}

Advertisements