gpt4 book ai didi

c# - 如何在 where 子句中使用 LINQ Except()

转载 作者:太空宇宙 更新时间:2023-11-03 17:40:59 25 4
gpt4 key购买 nike

我无法理解如何正确使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com