Clash 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);
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.
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