With linq I have to check if a value of a row is present in an array.
The equivalent of the sql query:
WHERE ID IN (2,3,4,5)
How can I do it?
With linq I have to check if a value of a row is present in an array.
The equivalent of the sql query:
WHERE ID IN (2,3,4,5)
How can I do it?
or
Perform the equivalent of an SQL IN with IEnumerable.Contains().
Following is a generic extension method that can be used to search a value within a list of values:
This can be used as:
This is handy in conditional statements.
.Contains
Of course, with your simple problem, you could have something like:
You can write help-method:
and use short code:
An
IEnumerable<T>.Contains(T)
statement should do what you're looking for.