从CRMService获取相关实体

时间:2012-03-23 23:55:15

标签: c# dynamics-crm crm dynamics-crm-4

我正在尝试构建一个从CRM4获取数据的sharepoint BCS连接器。我从“联系”权限获取正常属性,但我没有看到如何检索相关联系人,自定义实体或会议/约会等内容。

我已经读完了这些:

how to get related entities in dynamics CRM 2011

Retrieve a list of entites from CRM 2011, each with all of their related entities

Microsoft CRM, how do I get all the members of a list using CrmService?

但我似乎无法看到我正在做的事情。我正在使用普通的CRMService Web服务。我正在使用正常的请求:

var contacts = service.RetrieveMultiple(query);

除非我遗漏了某些东西,否则只能让我访问基本属性。如果联系人有几个与之相关的实体(其他联系人/会议),我可以从同一个查询中获取该实体吗?或者这是否需要再次击中另一个实体?

1 个答案:

答案 0 :(得分:1)

据我所知(并记住CRM 4),您必须独立查询每个实体。另一方面,您可以根据需要进行过滤:

var query = new QueryExpression
            {
                EntityName = "new_typedecontrat",
                ColumnSet = new ColumnSet { AllColumns = true },
                Criteria = new FilterExpression
                {
                    FilterOperator = LogicalOperator.And
                }
            };
            var expression2 = new ConditionExpression("new_typedecontratid",   ConditionOperator.Equal, campaign.New_TypedecontratId.Id);

            query.Criteria.Conditions.Add(expression2);

            EntityCollection entitys = CRM.Instance.RetrieveMultiple(query);



try
            {
                using (var serviceProxy1 = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null))
                {
                    // This statement is required to enable early-bound type support.
                    serviceProxy1.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
                    serviceProxy1.Timeout = new TimeSpan(0, 10, 0);
                    CRMService = serviceProxy1;

                    return CRMService.RetrieveMultiple(query);
                }
            }

这是否回答了你的问题?