Microsoft Dynamics CRM 2016

Я пытаюсь написать fetch xml для получения BusinessUnitID и Equipment ID из объекта Facility / Equipment, я написал этот fetch xml в коде C #, но он выдает исключение нулевой ссылки / 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"];
}

введите описание изображения здесь

Может кто-нибудь посоветовать мне это? Заранее спасибо!


person Rahul J    schedule 20.04.2016    source источник


Ответы (1)


Вам нужно добавить 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>";
person Guido Preite    schedule 20.04.2016
comment
Привет, Гвидо Прежде всего спасибо за ответ на вопрос. Я все еще получаю ту же ошибку. Пожалуйста, посмотрите на изображение, добавленное выше. - person Rahul J; 20.04.2016
comment
тогда _orgService не инициализируется данными вашего подключения - person Guido Preite; 20.04.2016
comment
Спасибо! возникла проблема с подключением. - person Rahul J; 20.04.2016