Dynamics crm CRM Dynamics Upsert-插入选项

Dynamics crm CRM Dynamics Upsert-插入选项,dynamics-crm,Dynamics Crm,我正在尝试更新/插入联系人实体。在保存简单文本字段时,更新OptiStart会遇到困难。例如,new_gender字段是一个选项集(男性/女性) 错误是: "new_gender should have the Integer value of Enum. Please supply it in the format - <entitysetname>(<attributename>=100000000)" “新的性别应该有Enum的整数值。请以-(

我正在尝试更新/插入联系人实体。在保存简单文本字段时,更新OptiStart会遇到困难。例如,
new_gender
字段是一个选项集(男性/女性)

错误是:

"new_gender should have the Integer value of Enum. Please supply it in the format - <entitysetname>(<attributename>=100000000)"
“新的性别应该有Enum的整数值。请以-(=100000000)的格式提供它”

感谢您的帮助

自定义选项集有一个名为选项值前缀的前缀。我猜在你的情况下是“10000”。 试着这样做:

contact["new_gender"] = new OptionSetValue(100000001);

您可以定义类似以下内容的枚举

public enum Gender
{
    Male = 10000001,
    Female = 10000002
}
并设置了性别属性

contact["new_gender"] = new OptionSetValue((int)Gender.Male);
另外,你可以得到这样的性别值

int value = ((OptionSetValue)contact[new_gender]).Value;

这没用。它给出了这个错误消息。“new_Seven应具有Enum的整数值。请以-(=100000000)的格式提供该整数值。”。我想格式应该如上所述。阳性和阴性选项的代码值是多少?我将代码值设置为1和2。没有其他数字发布者设置中的选项值前缀是什么?这是一条自定义错误消息。您必须为此检查代码库和枚举
int value = ((OptionSetValue)contact[new_gender]).Value;