OptionSetValueCollection 未采用空值。将值设置为 null 时引发一般 SQL 错误
OptionSetValueCollection not taking a null value. Throws Generic SQL error when setting up the value to null
我正在 CRM 插件中创建新记录(通过从相关记录中读取数据),我传递的数据可能包含/可能不包含 "OptionSetValueCollection"。只要 OptionSetValueCollection 的值为空,IOrganization.Create
就会抛出一个通用 SQL 异常。
目前我正在检查提交的值是否为空,如果不为空,我不会为创建的对象提交值。
我的问题是为什么 OptionSetValueCollection 不取 null?这是平台问题吗?
我还尝试创建一个 List<OptionSetValue>
对象并从 OptionSetValueCollection 添加传入的 OptionSetValues,然后将其传递给目标属性,尝试传递 null 并使用 null-coalescing operator all with no运气.
//Earlybound code
Account account = new Account(){
Name = newBrand,
new_accounttype = new OptionSetValue((int)new_AccountType.Brand),
TerritoryId = siteRequestRecord.new_territoryid,
new_category1 = siteRequestRecord.new_category1 ?? null,
};
if (category2 != null)
{
account.new_category2 = siteRequestRecord.new_category2;
}
service.Create(account);
据我所知,您想将 Optionset 设置为 null。使用下面的代码它应该工作并为您的选项集设置 null
new_accounttype = null;
Seems to be a long outstanding issue.
There is a bug related to multiselect optionset - if you set it to null during creation that will trigger an error. But the same code that sets field to null works fine during update.
So if you set it to null during Create just don't set field value and as a result you'll get blank value of a field.
我正在 CRM 插件中创建新记录(通过从相关记录中读取数据),我传递的数据可能包含/可能不包含 "OptionSetValueCollection"。只要 OptionSetValueCollection 的值为空,IOrganization.Create
就会抛出一个通用 SQL 异常。
目前我正在检查提交的值是否为空,如果不为空,我不会为创建的对象提交值。
我的问题是为什么 OptionSetValueCollection 不取 null?这是平台问题吗?
我还尝试创建一个 List<OptionSetValue>
对象并从 OptionSetValueCollection 添加传入的 OptionSetValues,然后将其传递给目标属性,尝试传递 null 并使用 null-coalescing operator all with no运气.
//Earlybound code
Account account = new Account(){
Name = newBrand,
new_accounttype = new OptionSetValue((int)new_AccountType.Brand),
TerritoryId = siteRequestRecord.new_territoryid,
new_category1 = siteRequestRecord.new_category1 ?? null,
};
if (category2 != null)
{
account.new_category2 = siteRequestRecord.new_category2;
}
service.Create(account);
据我所知,您想将 Optionset 设置为 null。使用下面的代码它应该工作并为您的选项集设置 null
new_accounttype = null;
Seems to be a long outstanding issue.
There is a bug related to multiselect optionset - if you set it to null during creation that will trigger an error. But the same code that sets field to null works fine during update. So if you set it to null during Create just don't set field value and as a result you'll get blank value of a field.