Find out the names of all the attributes in the object returned from CRM Dynamics

I hit the server and I received (hopefully) the correct dataset. Then I tried to list all the companies using 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 would be nice to start an inner loop that goes through all the available attributes in result.Entities. Should I use entity.Attributes.Keysor is there a better method?

+5
source share
2 answers

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);
    }
} 
+8
source

Performs a task using the Lambda expression.

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);
}
0
source

All Articles