我无法理解如何正确使用 Except()。 我想在 where 子句 中使用 Except() 来排除与字符串列表匹配的结果。我编了下面这个简单的例子来说明。
此外,在这种情况下使用 Except 是最快的方法吗?如果不是,什么会更快?
我在哪里:
var result = (from FunTable in Context.t_FunTable
where FunTable.ft_FunStartDate >= startDate
&& FunTable.ft_FunEndDate <= endDate
----> && FunTable.ft_FunStage != notAllowedStage1
----> && FunTabble.ft_FunStage != notAllowedStage2
select FunTable.ActivityName).ToList<String>();
我想这样做:
var result = (from FunTable in Context.t_FunTable
where FunTable.ft_FunStartDate >= startDate
&& FunTable.ft_FunEndDate <= endDate
----> && FunTable.ft_FunStage.Except(ListOfNotAllowedStages)
select FunTable.ActivityName).ToList<String>();
最佳答案
您可以使用 Contains
代替:
!ListOfNotAllowedStage.Contains(FunTable.ft_FunStage)
或任何
:
!ListOfNotAllowedStage.Any(x => x == FunTable.ft_FunStage)
关于c# - 如何在 where 子句中使用 LINQ Except(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22700008/