C# 为什么在搜索具有OptionSetValue属性的实体时必须使用int,而在创建实体时必须使用OptionSetValue对象?

C# 为什么在搜索具有OptionSetValue属性的实体时必须使用int,而在创建实体时必须使用OptionSetValue对象?,c#,c#-4.0,dynamics-crm-2011,C#,C# 4.0,Dynamics Crm 2011,我看到了CRM SDK如何处理通过OptionSetValue属性搜索实体和使用OptionSetValue属性创建实体的矛盾 背景: 我有一个带有这个签名的方法 GetOrCreateEntity<T>(IOrganizationService service, params object[] columnNameAndValuePairs) GetOrCreateEntity(IOOrganizationService服务,参数对象[]列名和值对) 其中columnNameA

我看到了CRM SDK如何处理通过OptionSetValue属性搜索实体和使用OptionSetValue属性创建实体的矛盾

背景: 我有一个带有这个签名的方法

GetOrCreateEntity<T>(IOrganizationService service, params object[] columnNameAndValuePairs)
GetOrCreateEntity(IOOrganizationService服务,参数对象[]列名和值对)
其中columnNameAndValuePairs是一个如下所示的对列表:(列的字符串名称,列的值),即“name”,“John Doe”转到entity.name=“John Doe”

它可以这样使用:

var user = GetOrCreateEntity<SystemUser>("username", "jdoe");
var user = GetOrCreateEntity<SystemUser>("username", "jdoe", "Sex", new OptionSetValue(1));
var user = GetOrCreateEntity<SystemUser>("username", "jdoe", "Sex", 1);
var user=GetOrCreateEntity(“用户名”、“jdoe”);
它将为用户名为jdoe的SystemUser实体创建并执行查询表达式。如果找不到,它将创建一个,用“jdoe”填充username属性,然后创建对象

问题: 这在大多数情况下都非常有效,除非我正在搜索/创建OptionSetValue属性。这样说吧:

var user = GetOrCreateEntity<SystemUser>("username", "jdoe");
var user = GetOrCreateEntity<SystemUser>("username", "jdoe", "Sex", new OptionSetValue(1));
var user = GetOrCreateEntity<SystemUser>("username", "jdoe", "Sex", 1);
var user=GetOrCreateEntity(“用户名”、“jdoe”、“性别”,新选项设置值(1));
var user=GetOrCreateEntity(“用户名”、“jdoe”、“性别”,1);
如果我传入
OptionSetValue(1)
查询表达式搜索失败,但是如果传入
1
查询表达式执行时不会出错,但是
服务.Create(entity)
会失败,因为它需要OptionSetValue


检查OptionSetValue值并将int值发送到QueryExpression对我来说很容易,但我只是想确保我没有做错什么。Microsoft是否真的希望您创建实体,将属性填充为OptionSetValue,但将其搜索为int?

我不能代表Microsoft说话,但这听起来/看起来是正确的。可能需要注意的是,您可以使用FetchXml或QueryExpression进行搜索,它们与用于创建/更新的DynamicEntity(CRM 4)或实体(CRM 2011)具有不同的模式


即使在CRM 4中,CRM有用于常见类型(CrmBoolean、CrmNumber)的WApper,您也必须按CLR类型进行查询,但必须使用包装器进行创建/更新。还要注意,EntityReference是相同的场景。您可以按Guid进行搜索,但必须使用EntityReference创建/更新。

所以基本上我没有做错任何事情,这就是Microsoft设置它的方式?