0
       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 ));

Let me explain my question with an example: For instance SelectOptionComp equals "-", then I want to ignore the parts where I used SelectOptionComp in longlinq or set SelectOptionComp to " " in the longlinq. I don't want to use ifs because of large number of combinations. How do I do that?

E__
  • 45
  • 8
  • Both works for me. @TimSchmelter – E__ Jan 11 '23 at 13:54
  • 2
    There are many questions and answers on how to add predicates (where filters) conditionally. For example: https://stackoverflow.com/a/14622200/861716 – Gert Arnold Jan 11 '23 at 14:29
  • Use the ternary operator: `(SelectOptionComp == "-" ? true : (x.Component.Components == SelectOptionComp || x.Component.Boards == SelectOptionComp))` – NetMage Jan 11 '23 at 19:39

1 Answers1

0

I have used ternary operator Use the ternary operator: (SelectOptionComp == "-" ? true : (x.Component.Components == SelectOptionComp || x.Component.Boards == SelectOptionComp))

E__
  • 45
  • 8