Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

QueryExpression for all Related Entities

(0) ShareShare
ReportReport
Posted on by 135

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

  • Suggested answer
    CRM-Dev Profile Picture
    CRM-Dev 135 on at
    RE: QueryExpression for all Related Entities

    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

                   }

  • CRM-Dev Profile Picture
    CRM-Dev 135 on at
    RE: QueryExpression for all Related Entities

    I need to find the related entities not the records of the related entities.

  • Suggested answer
    Nuno Profile Picture
    Nuno 2,005 on at
    RE: QueryExpression for all 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")));
    


  • Inogic Profile Picture
    Inogic 24,102 on at
    RE: QueryExpression for all Related Entities

    If you want to retrieve all the related records then you can retrieve entity relationships using metadata.

    Then retrieve related records using each relationship.

  • Suggested answer
    Faizal Profile Picture
    Faizal 545 on at
    RE: QueryExpression for all Related Entities

    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?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans