Will this expression do it?
s => s.Type.ToString().ToCharArray().Except(p.ToCharArray()).Count() == 0
eg. if s.Type
is 24
and p
is "234"
, then s.Type
included in the string. If we convert int
to char -array, we get
{'2', '4'}
String converted to char -array,
{'2', '3', '4'}
This means that the digits int
all included in the string
. Thus, the digits int
, in addition to the digits string
, give an empty set, which we test using Count() == 0
.
{'2', '4'}.Except({'2', '3', '4'}) ==> { }
Instead of creating a string
I would create a List<char>
var p = new List<char>(); if (saljes == "on") p.Add('1'); if (kopes == "on") p.Add('2'); if (bytes == "on") p.Add('3'); if (erbjudes == "on") p.Add('4');
Then the expression becomes
s => s.Type.ToString().ToCharArray().Except(p).Count() == 0
However, keep in mind that this cannot be converted to the corresponding SQL-where clause. Therefore, the entire table will need to be scanned.
source share