I am trying to build a QueryExpression in C# to get all related entities for a given parent entity.
Could you please help me with this task?
Thanks.
*This post is locked for comments
I go it:
RetrieveEntityRequest retrieveBankAccountEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Relationships,
LogicalName = 'account'
};
RetrieveEntityResponse retrieveBankAccountEntityResponse = (RetrieveEntityResponse)service.Execute(retrieveBankAccountEntityRequest);
var oneToNRelationships = retrieveBankAccountEntityResponse.EntityMetadata.OneToManyRelationships;
foreach (var oneToNRelationship in oneToNRelationships)
{
// your code
}
I need to find the related entities not the records of the related entities.
Hi,
QueryExpression query = new QueryExpression("ChildEntityLogicalName"); query.Criteria = new FilterExpression(LogicalOperator.And); query.Criteria.AddCondition(new ConditionExpression("AttributeChildEntityEntityReferenceToParentEntity", ConditionOperator.Equal, new Guid("GuidOfParententity")));
If you want to retrieve all the related records then you can retrieve entity relationships using metadata.
Then retrieve related records using each relationship.
Hi CRM Dev,
Did you mean to get ALL related entities for given parent entity?
or ALL records in specified one/more related entity for given record in parent entity?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,188 Super User 2024 Season 2
Martin Dráb 230,030 Most Valuable Professional
nmaenpaa 101,156