我正在尝试从设备查询业务单位ID,但我收到错误
QueryExpression qe = new QueryExpression();
qe.EntityName = "equipment";
qe.ColumnSet = new ColumnSet();
qe.ColumnSet.AddColumns("equipmentid", "name", "businessunitid");
qe.Criteria.AddCondition("name", ConditionOperator.Equal,EquipmentDropdown.Text);
EntityCollection resultequipments = _orgService.RetrieveMultiple(qe);
if(resultequipments.Entities.Count > 0)
{
Equipmentid = (Guid)resultequipments.Entities[0]["equipmentid"];
Buid = (Guid)resultequipments.Entities[0]["businessunitid"]; // error at this line
}
有人请帮忙 提前致谢
答案 0 :(得分:1)
如果您调试代码,您将看到businessunitid属性是EntityReference,而不是Guid。这样做:
var entityRef = (EntityReference)resultequipments.Entities[0]["businessunitid"];
var Buid = entityRef.Id;
答案 1 :(得分:0)
你必须创建一个循环来读取entityCollection
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "name";
condition.Operator = ConditionOperator.NotNull;
condition.Values.Add(EquipmentDropdown.Text);
ColumnSet columns = new ColumnSet("equipmentid", "name", "businessunitid");
QueryExpression qe = new QueryExpression();
qe.EntityName = "equipment";
qe.ColumnSet = columns;
EntityCollection resultequipments = _serviceProxy.RetrieveMultiple(qe);
foreach(Entity r in resultequipments.Entities)
{
Console.WriteLine( r.Attributes["equipmentid"]);
Console.WriteLine(r.Attributes["businessunitid"]); // error at this line
}
}
}