Dynamics crm 计算与该特定公司相关的每个人的其他关系

Dynamics crm 计算与该特定公司相关的每个人的其他关系,dynamics-crm,Dynamics Crm,我正在使用QueryExpression检索MSCRM 2016中某公司的所有连接 它为我提供了类似“员工”、“总经理”或“董事会成员”的record2roleid 但是我想计算这个人可能与其他公司的所有其他关系,比如如果一个董事会成员坐在3家公司里,那么子连接会给我计算:3 这就是我现在拥有的: //guid for the company Cola Cola Inc, for example guid accountid = "8e7fbd04-d12a-443a-998b-e0ea5801

我正在使用QueryExpression检索MSCRM 2016中某公司的所有连接

它为我提供了类似“员工”、“总经理”或“董事会成员”的record2roleid

但是我想计算这个人可能与其他公司的所有其他关系,比如如果一个董事会成员坐在3家公司里,那么子连接会给我计算:3

这就是我现在拥有的:

//guid for the company Cola Cola Inc, for example
guid accountid = "8e7fbd04-d12a-443a-998b-e0ea5801f315"            

//first we retrieve every connection for this company
var query = new QueryExpression("connection")
                {
                    ColumnSet = new ColumnSet("connectionid", "record2id", "record2roleid")
                };

//all connections that are connected to Coca Cola Inc
query.Criteria.AddCondition(new ConditionExpression("record1id", ConditionOperator.Equal, accountid));
//just the active ones
query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));

//link to contact for more detailed information about the person
query.LinkEntities.Add(new LinkEntity("connection", "contact", "record2id", "contactid", joinOperator: JoinOperator.LeftOuter)
{
EntityAlias = "contact",
Columns = new ColumnSet("fullname", "address1_name", "regno")

//count connections for this individual, by joining connection from contact and count all relations that contact has to other companies

});

任何帮助都将不胜感激

现在,您可以通过此查询循环检索联系人,以获取他们与此帐户以外的帐户的连接,并在检索后对他们进行计数

或者,你可以做一个简单的计算直接得到计数

<fetch distinct='false' mapping='logical' aggregate='true'> 
    <entity name='opportunity'> 
       <attribute name='name' alias='opportunity_count' aggregate='countcolumn' /> 
       <attribute name='ownerid' alias='ownerid' groupby='true' /> 
    </entity> 
</fetch>";
var linqQuery2 = (from f in linqQuery.ToList()
    group f by f.OwnerId into myGroup
    select new
    {
        OwnerName = myGroup.First().OwnerName,
        OrderCount = myGroup.Count()
    });