我正在尝试运行一个 LINQ 查询,该查询获取特定类型 [new_contact] 的所有对象,但过滤掉那些具有与列表 [excludeIdentifiers] 匹配的特定字段值 [new_identifier] 的对象。
public static List<new_placement>ActivityCounter(Account account, CRM2011DataContext CRMcontext)
{
int[] excludedIdentifiers = { 6, 7, 8, 9, 13, 14, 19, 20, 38, 39, 40, 41, 42, 43, 44, 45 };
var myActivities = (from a in CRMcontext.new_placementSet
where
!(a.new_entity_identifier.Value.Equals(excludedIdentifiers))
select new new_placement() { ActivityId = a.ActivityId }).ToList();
return myActivities;
}
}
我收到这个错误:
System.ServiceModel.FaultException`1 occurred
HResult=0x80131501
Message=Condition for attribute 'new_placement.new_entity_identifier': expected argument(s) of type 'System.Int32' but received 'System.Int32[]'.
Source=<Cannot evaluate the exception source>
StackTrace:<Cannot evaluate the exception stack trace>
我确定错误是由第五行引起的(因为没有它它运行良好):
!(a.new_entity_identifier.Value.Equals(excludedIdentifiers))
我在本地使用 Visual Studio 2017 和 CRM 2016 以及 Windows 10。Google 返回给我的答案至少已有七年历史,不够具体且不适合我。
最佳答案
错误消息准确地描述了您的问题,您正在尝试将 Int 值与 array of Int 进行比较。
您需要更改行 !(a.new_entity_identifier.Value.Equals(excludedIdentifiers))
类似于 !excludedIdentifiers.Contains(a.new_entity_identifier.Value)
关于c# - 在连接到 CRM 的 LINQ 表达式中排除数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44539693/