Reputation: 33
I'm trying to retrieve data from both parent and child entity in MS CRM.
I wrote the code in QueryExpression Class
I want to know how to add "OR" condition in LinkedEntity Query in QueryExpression
Class.
expOpp.LinkEntities[0].LinkCriteria.Conditions.Add(new ConditionExpression("statecode", ConditionOperator.Equal, 1));
In the above code i need to add "OR" condition.
Please help me how to make it.
Thanks in advance
Upvotes: 0
Views: 3912
Reputation: 1499
You can add an "or" condition on a linked entity like this (thank you henk for updating my knowledge!):
var queryExpression = new QueryExpression("contact");
var linkToAccount = queryExpression.AddLink("account", "parentcustomerid", "accountid");
linkToAccount.LinkCriteria.FilterOperator = LogicalOperator.Or;
linkToAccount.LinkCriteria.Conditions.Add(new ConditionExpression("field1", ConditionOperator.Equal, true));
linkToAccount.LinkCriteria.Conditions.Add(new ConditionExpression("field2", ConditionOperator.Equal, 100000001));
queryExpression.LinkEntities.Add(linkToAccount);
Or what you can also do is create an "or" filter on the linked entity and add conditions to that:
var queryExpression = new QueryExpression("contact");
var linkToAccount = queryExpression.AddLink("account", "parentcustomerid", "accountid");
var filter = linkToAccount.LinkCriteria.AddFilter(LogicalOperator.Or);
filter.Conditions.Add(new ConditionExpression("field1", ConditionOperator.Equal, true));
filter.Conditions.Add(new ConditionExpression("field2", ConditionOperator.Equal, 100000001));
queryExpression.LinkEntities.Add(linkToAccount);
Upvotes: 2