C# 排除连接到CRM的LINQ表达式中的数组

C# 排除连接到CRM的LINQ表达式中的数组,c#,linq,visual-studio-2017,dynamics-crm-2016,C#,Linq,Visual Studio 2017,Dynamics Crm 2016,我试图运行一个LINQ查询,该查询获取特定类型[new_contact]的所有对象,但过滤掉那些具有特定字段值[new_identifier]且与列表[excludeIdentifiers]匹配的对象 public static List<new_placement>ActivityCounter(Account account, CRM2011DataContext CRMcontext) { int[] excludedIdentifiers = { 6, 7, 8, 9

我试图运行一个LINQ查询,该查询获取特定类型[new_contact]的所有对象,但过滤掉那些具有特定字段值[new_identifier]且与列表[excludeIdentifiers]匹配的对象

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;
    }
}

我正在使用VisualStudio2017和CRM 2016内部部署和Windows10。谷歌返回的答案至少有七年历史,不够具体,对我来说也不合适。

错误消息准确地描述了您的问题,您试图将Int值与Int数组进行比较

您需要更改行
!(a.new\u entity\u identifier.Value.Equals(不包括标识符))


类似于
!excludedIdentifiers.Contains(一个新的实体标识符.Value)

我能够以一种更“手动”的方式使它工作。它既不美观,也不灵活,但很有效

public static List<new_placement>ActivityCounter(Account account, CRM2011DataContext CRMcontext)
{
var myActivities = (from a in CRMcontext.new_placementSet
                         where
                         a.new_entity_identifier.Value != 6
                         a.new_entity_identifier.Value != 7
                         a.new_entity_identifier.Value != 8
                         a.new_entity_identifier.Value != 9 // And so on..
                             select new new_placement() { ActivityId = a.ActivityId }).ToList();
    return myActivities;
}
publicstaticlistActivityCounter(帐户帐户,CRM2011DataContext CRMcontext)
{
var myActivities=(来自CRMcontext.new\u placementSet中的
哪里
a、 新建实体标识符.Value!=6
a、 新实体标识符.Value!=7
a、 新实体标识符.Value!=8
a、 新的\u实体\u identifier.Value!=9//依此类推。。
选择new_placement(){ActivityId=a.ActivityId});
返回我的活动;
}

我的同事刚刚通知我,Linq不能在CRM中使用Contains方法。为什么?Enumerable.Contains和Entity.Contains之间是否存在歧义?@ToFo我不明白为什么会有这样的限制。也许我误解了注释,但是对数组/列表/枚举表调用了.Contains()方法,CRM应该不会对其产生任何影响。@Janupienaar,只是这是一个LINQ to SQL查询,get被翻译成一个查询表达式,在服务器上执行,然后返回。我也以这种丑陋的方式结束了它。有人看到更好的解决方案吗?
!(a.new_entity_identifier.Value.Equals(excludedIdentifiers))
public static List<new_placement>ActivityCounter(Account account, CRM2011DataContext CRMcontext)
{
var myActivities = (from a in CRMcontext.new_placementSet
                         where
                         a.new_entity_identifier.Value != 6
                         a.new_entity_identifier.Value != 7
                         a.new_entity_identifier.Value != 8
                         a.new_entity_identifier.Value != 9 // And so on..
                             select new new_placement() { ActivityId = a.ActivityId }).ToList();
    return myActivities;
}