R. Matveev R. Matveev - 1 year ago 118
C# Question

CRM : Liked Entities collection is empty

I have the following query to get account with related entity = primary contact. Executing this query I successfully get accounts, but related entity collection is empty.

var _service = _getService();
var q = new QueryExpression("account");
q.ColumnSet = new ColumnSet("name");

q.LinkEntities.Add(new LinkEntity("account", "contact",
"primarycontactid", "contactid", JoinOperator.Inner));
q.LinkEntities[0].Columns.AllColumns = true;
q.LinkEntities[0].EntityAlias = "temp";

EntityCollection ec = _service.RetrieveMultiple(q);

What am I doing wrong?

Update 1: to check related entities fields I use

for (int i = 0; i < ec.Entities.Count; i++)
Console.Write(ec.Entities[i].RelatedEntities.Count + " ");

Answer Source

Just to be clear when you join entities in that way all the related entity information (contact in your case) will be returned along with fields of primary entity (account in your case). To get field from related entity you will have to check the same entity like (string)ec.Entities[0].GetAttributeValue("temp.fullname").Value

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download