LINQ查询过滤DTO

时间:2010-05-21 19:14:15

标签: c# linq-to-objects

我有一个数组......我需要从masterList.customField中排除此数组字符串中的所有项目,如下所示

string[] excludeItem = {"a","b","c"};

CustomDTO[] masterList = service.LoadMasterList();

masterList.Where(c=> masterList.customField NOT IN excludeItem

如何实现上面的NOT IN部分?

2 个答案:

答案 0 :(得分:3)

假设customField是一个字符串:

masterList.Where(c => !excludeItem.Contains(c.customField));

答案 1 :(得分:0)

或者,作为LINQ查询:

var x = from c in masterList
        where !excludedItem.Contains(c.CustomField)
        select c;