以编程方式检索所有子/后代/相关实体

时间:2014-08-12 09:31:44

标签: c# dynamics-crm-2011 dynamics-crm entities

如何在C#中检索CRM Dynamics 2011中源实体的所有相关实体?

感谢

1 个答案:

答案 0 :(得分:1)

FetchXml对于这个要求来说太过分了,但很明显,如果你想构建FetchXml并用QueryBase来代替QueryExpression,我可以自由地做到这一点。逻辑保持不变。

//Assumes you have a Entity() object of the parent entity
//somehow you have to know the parent entity record's Id

Guid parentId = parentEntity.Id;
var query = new QueryExpression("new_childentity");
query.Criteria.AddCondition(new ConditionExpression("new_lookupfield", ConditionOperator.Equal, parentId));
query.ColumnSet = new ColumnSet(true);
var results = service.RetrieveMultiple(query);
if (results.Entities.Any())
{
     //Do your processing here
}
else
{
     //Do whatever when there are no child entities
}