fetchXml или QueryExpression
Собственно
1. Вариант с xml
Код:
xml = @"
<fetch distinct='false' version='1.0' output-format='xml-platform' mapping='logical' aggregate='true'>
<entity name='contact'>
<attribute name='contactid' alias='contact_count' aggregate='count'/>
<filter type='and'>
<condition attribute='parentcustomerid' operator='eq' value='" + accountId.ToString() + @"' />
</filter>
<link-entity name='alv_roleline' to='alv_role' from='alv_rolelineid' visible='false' alias='a_97dcd59da0d7e11188bb00155d016705'>
<filter type='and'>
<condition attribute='alv_rolecode' operator='eq' value='head' />
</filter>
</link-entity>
</entity>
</fetch>";
resultEntity = service.RetrieveMultiple(new FetchExpression(xml)).Entities.First();
count = (int)resultEntity.GetAttributeValue<Microsoft.Xrm.Sdk.AliasedValue>("contact_count").Value;
if (count == 0)
{
SetCollectInfo(service, accountId, false);
return;
}
2, Вот QueryExpression
Код:
qe = new QueryExpression(Contact.EntityLogicalName);
qe.Criteria.AddCondition("parentcustomerid", ConditionOperator.Equal, accountId);
{
LinkEntity le = new LinkEntity(Contact.EntityLogicalName, alv_RoleLine.EntityLogicalName, "alv_role", "alv_rolelineid", JoinOperator.Inner);
le.LinkCriteria.AddCondition("alv_rolecode", ConditionOperator.Equal, "head");
qe.LinkEntities.Add(le);
}
if (service.RetrieveMultiple(qe).Entities.Count == 0)
{
SetCollectInfo(service, accountId, false);
return;
}
Мне кажется что первое будет быстрее работать

А чтоб не казалось, кто знает точно?)