使用QueryExpression无法从实体获取整数属性

时间:2014-06-14 11:06:41

标签: dynamics-crm-2011

基本上,我试图从实体获取一个整数属性来赋值,但是当我在check中检查时,只有" new_name"和" new_firmid"所显示的属性。

Entity entity = new Entity("new_firm");

ConditionExpression condition = new ConditionExpression("new_name", ConditionOperator.Equal, "Firm");
QueryExpression query = new QueryExpression(entity.LogicalName);
query.ColumnSet = new ColumnSet("new_name","new_number");
query.Criteria = new FilterExpression();
query.Criteria.Conditions.Add(condition);

EntityCollection collection = service.RetrieveMultiple(query);

collection.Entities[0].Attributes["new_number"] = (int) collection.Entities[0].Attributes["new_number"] + 10;

service.Update(collection.Entities[0]);

1 个答案:

答案 0 :(得分:0)

您没有在实体属性中看到属性new_number,因为该值为空。

在应用新值之前,您需要检查此条件,例如:

if (collection.Entities[0].Contains("new_number")) {
   collection.Entities[0].Attributes["new_number"] = (int)collection.Entities[0].Attributes["new_number"] + 10;
} else {
   collection.Entities[0].Attributes["new_number"] = 10; // assuming that empty equals 0
}