【发布时间】:2017-12-11 19:19:23
【问题描述】:
我最近在我的插件的一个方法中遇到了一个 OptionSetValue 表现得像一个整数。以前,与所有其他 OptionSetValues 一起,为了检索整数值,我使用了以下模式:
localIntegerVariable = (new_myEntity.GetAttributeValue<OptionSetValue>("new_myOptionSetAttribute")).Value;
这不再适用于插件的方法之一。如果我把它当作一个整数,它就可以工作。
localIntegerVariable = (new_myEntity.GetAttributeValue<int>("new_myOptionSetAttribute"));
奇怪的是,在我检索前图像实体之前,在同一插件的主要部分中,我将相同的属性视为 OptionSetValue 如下所示,它工作得很好。
int incominglocalIntegerVariable = temp.GetAttributeValue<OptionSetValue>("new_myOptionSetAttribute") == null ? _OSV_Empty : temp.GetAttributeValue<OptionSetValue>("new_myOptionSetAttribute").Value;
我已经验证entities.cs 文件中new_myOptionSetAttribute 的定义是一个OptionSetValue。我还验证了 CRM 中的定义是一个 OptionSet 值。
有人经历过吗?
【问题讨论】:
-
'不再工作'是什么意思?
-
当它到达这个语句时: localIntegerVarialbe = new_myEntity.GetAttributeValue
("new_myOptionSetAttribute ").Value 它返回以下错误。我们将 OptionSetValue.Value (int) 转换为整数,但似乎抱怨我们无法将 int 转换为 OptionSetValue InvalidCastException: Unable to cast object of type 'System.Int32' to type 'Microsoft.Xrm.Sdk.OptionSetValue ' -
您为 localIntegerVariable 声明的数据类型是什么?
标签: c# plugins dynamics-crm