我正在尝试编写一个fetch xml来从Facility / Equipment Entity中检索BusinessUnitID和Equipment ID,我已经在c#代码中编写了这个fetch xml,但它在行中抛出了一个null引用异常/ System.NullReferenceException(BOLD' ed line) 我在设施/设备实体中没有任何空值。 这是我的代码:
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"];
}
有人可以就此建议我吗? 提前谢谢!
答案 0 :(得分:4)
您还需要在属性中添加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>";