How to retreive an entity according to multiple linkentities?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to retreive an entity according to multiple linkentities?



I retrieve an Entity according to filtering with another entity, I need to add another filtering level- adding a linkentity to current link entity, Is it possible? What is the way to write it?


linkentity



This is my current code that works fine.


QueryExpression query = new QueryExpression("entity1");
query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
query.ColumnSet = new ColumnSet("entity1Id");
LinkEntity Link = new LinkEntity("entity1", "entity2", "entity2Id", "entity2Id", JoinOperator.LeftOuter);
Link.LinkCriteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
Link.Columns = new ColumnSet("entity2Data");
Link.EntityAlias = "entity2";
query.LinkEntities.Add(Link);



for conclusion: I need to add filtering to entity2 according to entity3.



UPDATE:I added this code:


QueryExpression query = new QueryExpression("entity1");
query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
query.ColumnSet = new ColumnSet(true);
LinkEntity portfolioLink = new LinkEntity("entity1", "entity2", "**entity2dI**", "entity2Id", JoinOperator.LeftOuter);
portfolioLink.LinkCriteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
query.LinkEntities.Add(portfolioLink);
LinkEntity portfolioLink2 = new LinkEntity("entity3", "entity2", "entity2Id", "entity2Id", JoinOperator.LeftOuter);
portfolioLink2.LinkCriteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
query.LinkEntities.Add(portfolioLink2);
EntityCollection characterizationeedsCollection = Service.RetrieveMultiple(query);



I get an exception that entity1 don't recognize entity2Id field, **entity1 field's name is unfortunately a little different ** but it worked fine before adding the third entity




2 Answers
2



It is same as 1st Link entity. In addition to existing code, add another Link entity like below:


LinkEntity Link2 = new LinkEntity("entity2", "entity3", "entity3Id", "entity3Id", JoinOperator.LeftOuter);
Link2.LinkCriteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
Link2.Columns = new ColumnSet("entity3Data");
Link2.EntityAlias = "entity3";
query.LinkEntities.Add(Link2);





I tried it but I get an error because my connecting field names of entity 1 and entity 2, are not the same as the connecting fields of entity2 and entity 3. it looks like all my connecting fields must be the same in all linked entities, is that right?
– Damkulul
Dec 31 '17 at 16:06





@Damkulul how’s that even possible, same schema name for FK of diff entities?
– Arun Vinoth
Dec 31 '17 at 16:16





I added my code my exception is that entity1 doesn't recognize entity3 field... Is my code ok ?
– Damkulul
Dec 31 '17 at 16:29





it seems that all entityLink I add is joined with the main entity and not filter in the different phase
– Damkulul
Dec 31 '17 at 16:37







@Damkulul: Am not sure if you can write sql query for what you are trying to achieve, which will help us to understand better. So what I could recommend is using xrmtoolbox fetchxml builder prepare the fetchxml query for same & compare it with your query.
– Arun Vinoth
Jan 1 at 1:57



Try using a FetchXml query instead. With this method you make your filter using Advanced Find. Then, in the window you download the FetchXml. It's by far easier to debug.



https://msdn.microsoft.com/en-us/library/gg328332.aspx






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP