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
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.
Thanks Mike,
however it seems that iOrganizationServiceContext requires references to *.Xrm.* which I don't have. I need to rely on CrmService calls.
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)
{
}
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,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156