简体   繁体   English

找出从CRM Dynamics返回的实体中所有属性的名称

[英]Find out the names of all the attributes in an entity returned from CRM Dynamics

I got myself into the server and I have retrieved (hopefully) the correct set of data. 我进入了服务器,我已经检索(希望)正确的数据集。 Then, I tried to list all the companies by the following code. 然后,我尝试通过以下代码列出所有公司。

EntityCollection result = proxy.RetrieveMultiple(expression);
foreach (var entity in result.Entities)
{
  String output = String.Empty;
  if (entity.Attributes.Contains("account"))
    output = entity.Attributes["account"].ToString();
}

However, it'd be nice to run an inner loop that goes through all the available attributes in result.Entities . 但是,运行一个遍历result.Entities所有可用属性的内部循环会很不错。 Should I use entity.Attributes.Keys or is there a better method? 我应该使用entity.Attributes.Keys还是有更好的方法?

I think this should do the trick. 我认为这应该可以解决问题。

foreach (Entity entity in result.Entities)
{
    foreach (KeyValuePair<String, Object> attribute in entity.Attributes)
    {
        Console.WriteLine(attribute.Key + ": " + attribute.Value);
    }
} 

This carries out the task using a Lambda expression. 这使用Lambda表达式执行任务。

EntityCollection result = proxy.RetrieveMultiple(expression);
foreach (var entity in result.Entities)
{
    var vsHeaders = entity.Attributes.Select(kvp => string.Format("{0}", kvp.Key));
    string sHeaders = string.Join(",", vsHeaders);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM