我正在使用 ConditionOperator.In 运算符编写带有过滤器的 QueryExpression,并将字符串作为值传递。但是,使用 CRM 服务器上的跟踪,我可以查看生成的 SQL,并且它正在用“1、2、3”替换我的字符串。
具体来说,这段代码:
var filter = new FilterExpression(LogicalOperator.And);
filter.AddCondition("primaryobjecttypecode", ConditionOperator.In, "account", "contact");
var query = new QueryExpression("sdkmessagefilter")
{
ColumnSet = new ColumnSet("primaryobjecttypecode"),
Criteria = filter,
LinkEntities =
{
new LinkEntity()
{
LinkFromEntityName = "sdkmessagefilter",
LinkFromAttributeName = "sdkmessageid",
LinkToEntityName = "sdkmessage",
LinkToAttributeName = "sdkmessageid",
Columns = new ColumnSet("name"),
},
}
};
var response = orgProxy.RetrieveMultiple(query);
此 SQL 的结果:
select top 5001
"sdkmessagefilter0".PrimaryObjectTypeCode as "primaryobjecttypecode",
"sdkmessage1".Name as "sdkmessage1.name"
from
SdkMessageFilter as "sdkmessagefilter0"
join SdkMessage as "sdkmessage1"
on ("sdkmessagefilter0".SdkMessageId = "sdkmessage1".SdkMessageId)
where
((("sdkmessagefilter0".PrimaryObjectTypeCode in (1, 2))))
order by "sdkmessagefilter0".SdkMessageFilterId asc
最终,由于未能将“1”作为字符串大小写,这会导致 SqlException。
为什么 {"account", "contact"} 字符串值会变成 {1, 2} int 值?
我在服务器上运行 Dynamics CRM 2011 UR 10,我的应用程序正在使用 SDK 5.0.9689.2166