Skip to main content



No record found.

Microsoft Dynamics CRM forum

How to get the related entities by code?

Posted on by 5

I am trying to get the collection of related entities and I am not succeeding.

My code:

using (var _service = new OrganizationServiceProxy(new Uri(url), null, clientCredentials, null))

    Guid _accountId = new Guid("e7385903-d01f-ea11-a810-000d3a654128");
    Guid _contactId = new Guid("ce30c7ae-cf1f-ea11-a810-000d3a654128");

    var filter = new FilterExpression();
    filter.AddCondition("accountid", ConditionOperator.Equal, _accountId);

    var account = RetrieveFirstOrDefault(filter);

    //How to fill in the account contacts

    return account;

I will appreciate any help, thank you.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get the related entities by code?

    Hi Juan,

    There are two ways you can get the related entities records.

    1. By Following below links:

    2. 2. Other way is using fetchxml:

    XRM toolbox -> Fetchxml builder.


    Right-click on fetch -> Add/Select parent entity -> Right click on Entity -> Add -> link-entity.


    Select Relationship with your link entity then fetchxml builder will auto-populate other fields.


    Using the generated fetchxml user can the linked entity records. On explore of this tool, you will find some more useful details.

  • Verified answer
    RE: How to get the related entities by code?

    So may I suppose you want to retrieve the account list whose contact field is equal to a specified contact record?

    You need to use link entity. Please refer to

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,773 Super User

Martin Dráb Profile Picture

Martin Dráb 225,513 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans