如何在C#中检索CRM Dynamics 2011中源实体的所有相关实体?
感谢
答案 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
}