如果变量等于特定值,忽略linq查询的部分内容


var longlinq = viewModel.Where(x => (x.Systems.Storage == SelectOption || x.Systems.Laptop == SelectOption ||
x.Systems._2In1 == SelectOption ||
x.Systems.Convertible == SelectOption ) 
||
(x.Component.Components == SelectOptionComp ||
x.Component.Boards == SelectOptionComp)
||
( x.Service.Services == SelectOptionSer ||
x.Service.DevelopmentTools_andServices == SelectOptionSer ) 
||
(x.Software.Softwares == SelectOptionSoft ||
x.Software.Analytics == SelectOptionSoft) 
||
(x.Application.Applications == SelectOptionApp ||
x.Application.PrintImaging_andOfficeAutomation ));
让我用一个例子来解释我的问题:例如,SelectOptionComp="-",然后我想忽略我使用的部分"longlinq"中的"SelectOptionComp"或"longlinq"中的"SelectOptionComp"设置为"" ""。我不想使用ifs,因为有大量的组合。我怎么做呢?

我使用了三元运算符Use the ternary operator: (SelectOptionComp == "-" ? true : (x.Component.Components == SelectOptionComp || x.Component.Boards == SelectOptionComp))

相关内容

  • 没有找到相关文章

最新更新