您好我想从CRM 2011中获取帐户。我正在获取EntityCollection中的数据。但是当我试图读取或访问entityCollection中的数据时,它显示第一条记录,但在该记录之后引发错误。请看下面的代码,并建议我。给定的密钥不存在于字典
string fetch2 = @"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='account'>
<attribute name='name' />
<attribute name='address1_city' />
<attribute name='primarycontactid' />
<attribute name='telephone1' />
<attribute name='accountid' />
<order attribute='name' descending='false' />
<filter type='and'>
<condition attribute='accounttype' operator='eq' value='01' />
</filter>
</entity>
</fetch>";
try
{
EntityCollection fxResult = _service.RetrieveMultiple(new FetchExpression(fetch2));
foreach (var e in fxResult.Entities)
{
Console.WriteLine("Id:{0},Name:{1},City:{2}", e.Attributes ["accountid"].ToString(), e.Attributes["name"].ToString(), e.Attributes["address1_city"].ToString());
// Console.WriteLine("Id:{0},Name:{1},City:{2}", e.ToEntity["accountid"]);
}
}
catch (Exception e)
{
Console.WriteLine("Error:==" + e.Message);
}
感谢您的帮助。我有一个对象类型的属性,我无法从该属性获取值。正如你的代码中所提到的,我可以检查并检索address1_city,因为它是字符串类型,但是我还有一个属性状态是哪个对象类型。我试图检查并检索它,但无法做到这一点。请建议 – user2897967
如果您有像“状态码”这样的属性,则必须将其转换为“OptionSetValue” – Sxntk