尝试从CRM记录中获取所有实体字段。 C#

时间:2014-11-12 12:18:00

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

直截了当,我正在尝试创建一个应用程序,以便用户可以在不进入CRM的情况下搜索他们的CRM系统。我已设法检索记录,但当我尝试使用记录属性将记录放入列表时,我只收到密钥。

以下是代码:

 EntityCollection retrieved = _service.RetrieveMultiple(query);
        foreach (var c in retrieved.Entities)
        {
            foreach (KeyValuePair<String, Object> attribute in c.Attributes)
            {
                lstRecordDetails.Items.Add(string.Format(attribute.Key + ": " + attribute.Value));
            }
        }

这只显示了recordID和Record Name,我知道这些都是记录的主要键,我知道我可以使用c.Attributes [&#34; description&#34;]来描述但是有一个我可以从记录中获取所有字段并将其显示在列表中的方式吗?

编辑:有关查询的详细信息

        QueryByAttribute query = new QueryByAttribute(entity);
        query.ColumnSet = new ColumnSet(field);

        query.Attributes.AddRange(field);
        query.Values.AddRange(selected);

2 个答案:

答案 0 :(得分:4)

您可以检索实体的所有列的方式是

query.ColumnSet = new ColumnSet(true);

但是,请注意这一点,因为查询所有列对系统有影响(您应该始终明确检索所需的列)。

答案 1 :(得分:0)

RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
retrieve.Query = query;
retrieve.ReturnDynamicEntities = true;

retrieved = (RetrieveMultipleResponse)Service.Execute(retrieve);

foreach(var dynEntity in retrieved.BusinessEntityCollection)
{
    foreach (var prop in dynEntity.Properties)
    {
        lstRecordDetails.Items.Add(string.Format("{0}:{1}", prop.Name, prop.Value);
    }
}