web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to get the related entities by code?

(0) ShareShare
ReportReport
Posted on by 5

Hello,
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))
{
    _service.EnableProxyTypes();

    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
    //account.ait_account_contact

    return account;
}


I will appreciate any help, thank you.

I have the same question (0)
  • Verified answer
    Steven RH JIANG Profile Picture
    Microsoft Employee on at

    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 https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/279405/how-to-use-filter-on-link-entity/797943

  • Verified answer
    Community Member Profile Picture
    on at

    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.

    1207.Picture1.png

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

    0284.Picture2.png

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

    0358.Picture3.png

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

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 90 Super User 2026 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 40 Most Valuable Professional

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 35 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans