I`m trying to use link entity instead of the xml, but I'm getting exception in the last row.
var accountQuery = new QueryExpression("account");
accountQuery.ColumnSet.AddColumns("name", "parentaccountid",
"parentaccountid","statuscode", "accountid");
LinkEntity entity = new LinkEntity()
{
LinkFromEntityName = "account",
LinkFromAttributeName = "parentaccountid",
LinkToEntityName = "childaccount",
LinkToAttributeName = "accountid",
JoinOperator = JoinOperator.LeftOuter,
Columns = new ColumnSet("name", "statuscode"),
EntityAlias = "childaccount"
};
accountQuery.LinkEntities.Add(entity);
FilterExpression Filter1 = new FilterExpression(LogicalOperator.Or);
Filter1.AddCondition("statuscode", ConditionOperator.Equal, _liveStatusCode);
Filter1.AddCondition("statuscode", ConditionOperator.Equal, _implemantation);
FilterExpression Filter2 = new FilterExpression();
Filter2.AddCondition("childaccount", ConditionOperator.Null, null);
FilterExpression mainFilter = new FilterExpression(LogicalOperator.And);
mainFilter.AddFilter(Filter1);
mainFilter.AddFilter(Filter2);
accountQuery.Criteria = mainFilter;
EntityCollection accountResult = organizationService.RetrieveMultiple(accountQuery);