我正在一个 .NET 项目中工作,该项目需要创建 QueryExpression 以根据输入的客户端全名过滤 CRM 记录。
var query = new QueryExpression
{
EntityName = Xrm.Contact.EntityLogicalName,
ColumnSet = cols
};
query.Criteria.AddCondition("statecode", ConditionOperator.Equal, (int)ContactState.Active);
query.Criteria.FilterOperator = LogicalOperator.And;
var subfilter = new FilterExpression(LogicalOperator.Or);
var conditionCheckFullNameEqualInput = new ConditionExpression("fullname", ConditionOperator.Equal, revenueEntity.ClientName);
subfilter.Conditions.Add(conditionCheckFullNameEqualInput);
var filterCheckInputContainedInFullName = new FilterExpression(LogicalOperator.And);
Regex rgx0 = new Regex("[^a-zA-Z0-9]");
var tmparr0 = rgx0.Split(revenueEntity.ClientName).Where(s => !DataFeedProviderInputValidator.IsEmptyValue(s)).ToArray(); ;
foreach (var tmparritem in tmparr0)
filterCheckInputContainedInFullName.AddCondition("fullname", ConditionOperator.Contains, tmparritem);//need to handle case-sensitive scenarios
subfilter.AddFilter(filterCheckInputContainedInFullName);
var filterCheckFullNameContainedInInput = new FilterExpression(LogicalOperator.And);
filterCheckFullNameContainedInInput.AddCondition("firstname", ConditionOperator.In, tmparr0);//need to handle case-sensitive scenarios
filterCheckFullNameContainedInInput.AddCondition("lastname", ConditionOperator.In, tmparr0);//need to handle case-sensitive scenarios
subfilter.AddFilter(filterCheckFullNameContainedInInput);
query.Criteria.Filters.Add(subfilter);
上面代码的问题是,如果在 CRM 上有一个全名的联系人,如“Fry, Paraskevi”,如果我的输入是“FRY PARASKEVI”,则无法匹配。但如果我的输入是“Fry Paraskevi”或“Paraskevi Fry”,它将完美匹配。有几条记录是这样的。
我的问题是,FilterExpression 是否支持过滤不区分大小写的 CRM 记录(如 String.IndexOf 或 String.Equals)?我应该怎么办?