0

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.

2
  • the queryexpression looks correct to me, keep in mind that because you are not doing a LinkCriteria, the query should return only accounts where name begins with "Cashmere" that has a primarycontactid filled. If you can put a screenshot of an advanced find query will be helpful to understand Commented Feb 1 at 22:42
  • You do not show the code that is processing the results. The contact fields will be returned as AliasedValue objects. Are you aware of that? Commented Feb 3 at 23:12

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.