Skip to main content

Retrieve many to many relation MS CRM 2016 query expression C#

string entity1 = "mzk_dosageform";
string entity2 = "mzk_ordersetup";
string relationshipEntityName = "mzk_mzk_dosageform_mzk_route";
        
LinkEntity linkEntity1 = new LinkEntity(entity1, relationshipEntityName, "mzk_dosageformid", "mzk_dosageformid", JoinOperator.Inner);

LinkEntity linkEntity2 = new LinkEntity(relationshipEntityName, entity2, "mzk_ordersetupid", "mzk_ordersetupid", JoinOperator.Inner);
linkEntity2.Columns = new Microsoft.Xrm.Sdk.Query.ColumnSet("mzk_ordersetupid", "mzk_code", "mzk_description");
linkEntity2.EntityAlias = "OrderSetup";
linkEntity1.LinkEntities.Add(linkEntity2);
query.LinkEntities.Add(linkEntity1);
linkEntity2.LinkCriteria = new FilterExpression();
linkEntity1.LinkCriteria.AddCondition(new ConditionExpression("mzk_dosageformid", ConditionOperator.Equal, Dosage));

SoapEntityRepository entityRepository = new SoapEntityRepository();
EntityCollection entitycollection = entityRepository.GetEntityCollection(query);



Thanks & Regards
Rizwan Ahmed
Microsoft Dynamics(AX/CRM) Technical Consultant

GTalk|LinkedIn|Twitter|Facebook|Blog|

Comments

Post a Comment