繁体   English   中英

Microsoft Dynamics CRM 2016年

[英]Microsoft Dynamics CRM 2016

我试图编写一个提取xml来从设施/设备实体中检索BusinessUnitID和设备ID,我已经用c#代码编写了此提取xml,但是它在行(粗体行)中引发了空引用异常/System.NullReferenceException。我在设施/设备实体中没有空值。 这是我的代码:

  private static OrganizationService _orgService;
  string fetchBU = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='equipment'>
        <attribute name='name' />
        <attribute name='equipmentid' />
        <order attribute='name' descending='false' />
      <filter type='and'>
         <condition attribute='businessunitid' operator='eq-businessid' />
      </filter>
    </entity>
   </fetch>";

EntityCollection ec = _orgService.RetrieveMultiple(new FetchExpression(fetchBU));
if (ec.Entities.Count > 0)
{
   Guid BusinessUnitId = (Guid)ec[0].Attributes["businessunitid"];
}

在此处输入图片说明

有人可以建议我吗? 提前致谢!

您不仅需要在以下条件中,还需要在属性内添加businessunitid

string fetchBU = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='equipment'>
        <attribute name='name' />
        <attribute name='equipmentid' />
        <attribute name='businessunitid' />
        <order attribute='name' descending='false' />
      <filter type='and'>
         <condition attribute='businessunitid' operator='eq-businessid' />
      </filter>
    </entity>
   </fetch>";

暂无
暂无

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

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