I am using the following code
QueryExpression query = new ("account") {
ColumnSet = new ColumnSet(
"accountid",
"name",
"primarycontactid"
),
Criteria = {
Conditions = {
new ConditionExpression("name", ConditionOperator.BeginsWith, "Cashmere")
}
}
};
LinkEntity le = query.AddLink(
linkFromAttributeName: "primarycontactid",
linkToEntityName: "contact",
linkToAttributeName: "contactid",
joinOperator: JoinOperator.Inner);
le.EntityAlias = "contact";
le.Columns = new ColumnSet("contactid","firstname","lastname","jobtitle");
var results = await _serviceClient.RetrieveMultipleAsync(query);
I have 3 results from the query all of which have a primarycontactid that exists in the Contact set however the link entity always returns 0. I have tried this with various different flavours and the link entity never has any results.
If I use a LINQ query, I am able to get both. What am I doing wrong with this QueryExpression.
I am using the following code
QueryExpression query = new ("account") {
ColumnSet = new ColumnSet(
"accountid",
"name",
"primarycontactid"
),
Criteria = {
Conditions = {
new ConditionExpression("name", ConditionOperator.BeginsWith, "Cashmere")
}
}
};
LinkEntity le = query.AddLink(
linkFromAttributeName: "primarycontactid",
linkToEntityName: "contact",
linkToAttributeName: "contactid",
joinOperator: JoinOperator.Inner);
le.EntityAlias = "contact";
le.Columns = new ColumnSet("contactid","firstname","lastname","jobtitle");
var results = await _serviceClient.RetrieveMultipleAsync(query);
I have 3 results from the query all of which have a primarycontactid that exists in the Contact set however the link entity always returns 0. I have tried this with various different flavours and the link entity never has any results.
If I use a LINQ query, I am able to get both. What am I doing wrong with this QueryExpression.
As Henk pointed out the results are AliasedValues but what the Microsoft documentation for LinkEntity and all their examples don’t show is how the LinkEntity items are returned.
I stumbled across the answer. The results appear in your main entity results in the Attributes field. They use the entityAlias and field name as the key, so if your entityAlias is ‘leAlias’ and your column include Name then the attribute key will be ‘leAlias.name’.
Additionally be careful to specify filter criteria or you can end up with duplicate entities with varying attributes.
AliasedValue
objects. Are you aware of that? – Henk van Boeijen Commented Feb 3 at 23:12