I have an expression tree built like this
Expression<Func<User, bool>> match = o =>
o.Name == viewModel.Name
&& orders.Contains(o.User.Company.CompanyId.ToString())
&& o.dept == viewModel.dept
I only want to include the line
o.dept == viewModel.dept
when viewModel.dept is 1, 2 or 3 and not include this condition in the expression tree, if it’s any other value.
This code is in a function that gets a viewModel as parameter and the values in the viewModel are used to query the EF model User.
Currently I have 2 separate expression trees to meet this scenario. Is there any better solution?
Thank you