排除出现在另一个序列中的元素

时间:2017-09-01 18:38:23

标签: linq

我有以下顺序:

public static List<string> IgnoredSubCodes => new List<string> {"HERE", "NOT_HERE"};

var demographics = personify.CUS_DEMOGRAPHIC.Where(demographic =>
                    clubIds.Contains(demographic.MASTER_CUSTOMER_ID) &&
                    distinctCodes.Contains(demographic.DEMOGRAPHIC_CODE) &&
                    distinctProgramYears.Contains(demographic.USR_PROGRAM_YEAR) &&
                    !demographic.DEMOGRAPHIC_SUBCODE.Any(x => PersonifyConstants.DemographicCodes.DemographicSubCodes.IgnoredSubCodes));

上面的最后一行不起作用,但我希望能够说“不要包含此列表中显示的任何人口统计子代码”。我怎样才能做到这一点?我已经尝试了几个不同的条款.Where和.Any但我不理解我需要的排列。我可以在查询中将其硬编码为demographic.DEMOGRAPHIC_SUBCODE != "HERE" && demographic.DEMOGRAPHIC_SUBCODE != "NOT_HERE",但我希望将所有排除项放在一个位置。

1 个答案:

答案 0 :(得分:0)

你可以尝试一下吗?希望它能奏效。

var demographics = personify.CUS_DEMOGRAPHIC.Where(demographic =>
                clubIds.Contains(demographic.MASTER_CUSTOMER_ID) &&
                distinctCodes.Contains(demographic.DEMOGRAPHIC_CODE) &&
                distinctProgramYears.Contains(demographic.USR_PROGRAM_YEAR) &&
                !PersonifyConstants.DemographicCodes.DemographicSubCodes.IgnoredSubCodes.Any(code => code == demographic.DEMOGRAPHIC_SUBCODE));