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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get related entities programmatically by 1:N relationship name (CRM 4.0)

(0) ShareShare
ReportReport
Posted on by

Hi All,

I have entity A and B with thousand records. A has a 1:N relationship named "new_Bs". What is the correct method to get the related Bs for a given A using Crm.Discovery.* APIs? (Not Xrm)

*This post is locked for comments

I have the same question (0)
  • st738407 Profile Picture
    227 on at

    In a plugin we use something like the below, where we use LINQ.  dds_opportunity_product_line is our child entity (B in your example).  Hope this helps.            

    using (OrganizationServiceContext orgContext = new OrganizationServiceContext(orgService))

               {

                   var oppEF = opportunity.GetAttributeValue<EntityReference>("opportunityid");

                   var OPLs = orgContext.CreateQuery("dds_opportunity_product_line").Where(p => p.GetAttributeValue<EntityReference>("dds_opportunity_name") ==

                       oppEF && p.GetAttributeValue<OptionSetValue>("statecode").Value == Constants.OptionSets.EntityState.Active).ToList();

                   if (OPLs.Count() == 0)

                   {

                       return;

                   }

                   foreach (var OppProd in OPLs)

                   {

                   }

  • Community Member Profile Picture
    on at

    Thanks Mike,

    however it seems that iOrganizationServiceContext requires references to *.Xrm.* which I don't have. I need to rely on CrmService calls.

  • Inogic Profile Picture
    709 on at

    If you are working on plugin, getting organization service context won’t be problem from you. For standalone application or website you can refer CRM assemblies (“Xrm.SDK”) that will resolve your Xrm issue.

    For CRM version earlier than 2016 you can refer SDK assembly Microsoft.Xrm.Client.dll, which will provide you functions to retrieve records using relationship. From 2016 you need to write a function which will retrieve records using Linq.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans